package com.dragon.mmochat.service;

import java.awt.Color;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.MmochatMain;
import com.dragon.mmochat.message.Mmochat_15_2S;
import com.dragon.mmochat.message.Mmochat_1_10S;
import com.dragon.mmochat.message.Mmochat_1_16S;
import com.dragon.mmochat.message.Mmochat_3_1S;
import com.dragon.mmochat.message.Mmochat_3_3S;
import com.dragon.mmochat.message.Mmochat_4_8S;
import com.dragon.mmochat.message.Mmochat_6_10C;
import com.dragon.mmochat.message.Mmochat_6_11C;
import com.dragon.mmochat.message.Mmochat_6_12C;
import com.dragon.mmochat.message.Mmochat_6_13C;
import com.dragon.mmochat.message.Mmochat_6_14C;
import com.dragon.mmochat.message.Mmochat_6_15C;
import com.dragon.mmochat.message.Mmochat_6_16C;
import com.dragon.mmochat.message.Mmochat_6_17C;
import com.dragon.mmochat.message.Mmochat_6_18C;
import com.dragon.mmochat.message.Mmochat_6_19C;
import com.dragon.mmochat.message.Mmochat_6_1C;
import com.dragon.mmochat.message.Mmochat_6_20C;
import com.dragon.mmochat.message.Mmochat_6_21C;
import com.dragon.mmochat.message.Mmochat_6_22C;
import com.dragon.mmochat.message.Mmochat_6_24C;
import com.dragon.mmochat.message.Mmochat_6_25C;
import com.dragon.mmochat.message.Mmochat_6_26C;
import com.dragon.mmochat.message.Mmochat_6_2C;
import com.dragon.mmochat.message.Mmochat_6_2S;
import com.dragon.mmochat.message.Mmochat_6_3C;
import com.dragon.mmochat.message.Mmochat_6_4C;
import com.dragon.mmochat.message.Mmochat_6_5C;
import com.dragon.mmochat.message.Mmochat_6_8S;
import com.dragon.mmochat.message.Mmochat_6_9C;
import com.dragon.mmochat.message.Mmochat_8_10S;
import com.dragon.mmochat.model.MmochatChenHao;
import com.dragon.mmochat.model.MmochatDailyActivity;
import com.dragon.mmochat.model.MmochatLockChatData;
import com.dragon.mmochat.model.MmochatPkRequest;
import com.dragon.mmochat.model.MmochatTeam;
import com.dragon.mmochat.model.battle.MmochatBattle;
import com.dragon.mmochat.model.enumType.MmochatBattleType;
import com.dragon.mmochat.model.enumType.MmochatChatChannelType;
import com.dragon.mmochat.model.enumType.MmochatChenHaoType;
import com.dragon.mmochat.model.enumType.MmochatDailyActivityType;
import com.dragon.mmochat.model.enumType.MmochatEquipPlaceType;
import com.dragon.mmochat.model.enumType.MmochatEquipType;
import com.dragon.mmochat.model.enumType.MmochatGangMemberType;
import com.dragon.mmochat.model.enumType.MmochatMultiPlayerTeamType;
import com.dragon.mmochat.model.enumType.MmochatOtherSystemSettingType;
import com.dragon.mmochat.model.enumType.MmochatPackageGridType;
import com.dragon.mmochat.model.enumType.MmochatPropEffectType;
import com.dragon.mmochat.model.enumType.MmochatPropType;
import com.dragon.mmochat.model.enumType.MmochatQickStartType;
import com.dragon.mmochat.model.enumType.MmochatRoleStateType;
import com.dragon.mmochat.model.enumType.MmochatServerType;
import com.dragon.mmochat.model.enumType.MmochatShowRoleSet;
import com.dragon.mmochat.model.enumType.MmochatSkillType;
import com.dragon.mmochat.model.enumType.MmochatTeamStateType;
import com.dragon.mmochat.model.gang.MmochatGang;
import com.dragon.mmochat.model.gang.MmochatGangMember;
import com.dragon.mmochat.model.gang.MmochatGangRequester;
import com.dragon.mmochat.model.map.MmochatMap;
import com.dragon.mmochat.model.object.MmochatCommonObject;
import com.dragon.mmochat.model.object.MmochatEquipAttribute;
import com.dragon.mmochat.model.object.MmochatPackageGrid;
import com.dragon.mmochat.model.object.MmochatPropEffect;
import com.dragon.mmochat.model.role.MmochatFriend;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.dragon.mmochat.model.skill.MmochatSkill;
import com.dragon.mmochat.util.CallLocalFuncTlv;
import com.dragon.mmochat.util.CreateTlvWin;
import com.dragon.mmochat.util.MmochatUtil;
import com.skymobi.handler.SkymobiHandler;
import com.skymobi.message.SkymobiProtocolMessage;
import com.skymobi.message.widget.AddDataTLV;
import com.skymobi.message.widget.AddEditBoxTLV;
import com.skymobi.message.widget.ClearDataTLV;
import com.skymobi.message.widget.CloseWinTLV;
import com.skymobi.message.widget.CreateEditBoxTLV;
import com.skymobi.message.widget.CreateMsgBoxTLV;
import com.skymobi.message.widget.CtrlTLVStructureRequest;
import com.skymobi.message.widget.SendDataTLV;
import com.skymobi.message.widget.ShowPopupMenuTLV;
import com.skymobi.message.widget.ShowWaitingMsgBoxTLV;
import com.skymobi.message.widget.WinType;
import com.skymobi.service.SkymobiService;
import com.skymobi.util.Text;

public class MmochatPlayerService {
	private static Logger log = LoggerFactory
			.getLogger(MmochatPlayerService.class);

	// 比武请求
	private static Map<Integer, MmochatPkRequest> pkRequestMap = new ConcurrentHashMap<Integer, MmochatPkRequest>();

	// 获取角色详细属性
	public static String getUserAttrInfo(MmochatPlayer me) {
		String content = "";
		content += MmochatUtil.wrapColor("角色名:", Color.green) + me.getName()
				+ "\n";
		content += MmochatUtil.wrapColor("ID:", Color.green)
				+ Integer.toHexString(me.getRoleId() * 3) + "\n";
		if (me.getSexual() == 0) {
			content += MmochatUtil.wrapColor("性别:", Color.green) + "男\n";
		} else {
			content += MmochatUtil.wrapColor("性别:", Color.green) + "女\n";
		}
		content += MmochatUtil.wrapColor("门派:", Color.green)
				+ me.getFamily().getName() + "\n";
		content += MmochatUtil.wrapColor("等级:", Color.green)
				+ me.getLevelInfo() + "\n";
		content += MmochatUtil.wrapColor("道行:", Color.green)
				+ MmochatUtil.getDaoSimpleString(me.getDao()) + "\n";
		content += MmochatUtil.wrapColor("战绩:", Color.green) + me.getZhanji()
				+ "\n";
		content += MmochatUtil.wrapColor("气血:", Color.green)
				+ me.getTotalBlood() + "\n";
		content += MmochatUtil.wrapColor("法力:", Color.green)
				+ me.getTotalSprit() + "\n";
		content += MmochatUtil.wrapColor("物伤:", Color.green)
				+ me.getPhysicalAttack() + "\n";
		content += MmochatUtil.wrapColor("法伤:", Color.green)
				+ me.getSpritAttack() + "\n";
		content += MmochatUtil.wrapColor("速度:", Color.green) + me.getSpeed()
				+ "\n";
		content += MmochatUtil.wrapColor("物防:", Color.green)
				+ me.getPhysicalDefend() + "\n";
		content += MmochatUtil.wrapColor("法防:", Color.green)
				+ me.getMagicDefend() + "\n";

		content += MmochatUtil.wrapColor("体质:", Color.green)
				+ me.getTotalBloodPoint() + "\n";
		content += MmochatUtil.wrapColor("力量:", Color.green)
				+ me.getTotalAttackPoint() + "\n";
		content += MmochatUtil.wrapColor("灵力:", Color.green)
				+ me.getTotalSpritPoint() + "\n";
		content += MmochatUtil.wrapColor("敏捷:", Color.green)
				+ me.getTotalSpeedPoint() + "\n";
		content += MmochatUtil.wrapColor("未分配属性:", Color.green)
				+ me.getSpace_point() + "\n";

		content += MmochatUtil.wrapColor("活力:", Color.green)
				+ me.getTotalBlood_gift_point() + "\n";
		content += MmochatUtil.wrapColor("坚韧:", Color.green)
				+ me.getTotalDefend_gift_point() + "\n";
		content += MmochatUtil.wrapColor("野蛮:", Color.green)
				+ me.getTotalAttack_gift_point() + "\n";
		content += MmochatUtil.wrapColor("智慧:", Color.green)
				+ me.getTotalSprit_gift_point() + "\n";
		content += MmochatUtil.wrapColor("灵巧:", Color.green)
				+ me.getTotalSpeed_gift_point() + "\n";
		content += MmochatUtil.wrapColor("未分配天赋:", Color.green)
				+ me.getSpace_gift_point() + "\n";
		return content;
	}

	// 返回查看其它玩家信息的窗体
	public static CreateTlvWin getUserInfoTlv(MmochatPlayer me, MmochatPlayer he) {
		// TODO
		if (he == null) {
			return null;
		}
		CreateTlvWin tlv = new CreateTlvWin();
		tlv.setWinType(WinType.Text);
		tlv.setRightName("返回");
		tlv.setTitle(he.getName());
		tlv.setWinHeight(208);
		tlv.addRightTLV(new CloseWinTLV());
		String detail = "";
		detail += MmochatUtil.wrapIcon(he.getBmpId())
				+ MmochatUtil.wrapColor(he.getName(), Color.green);
		// ID: roleId乘3转16进制
		detail += "\n[ID]:" + Integer.toHexString(he.getRoleId() * 3);
		detail += "\n[等级]:";
		if (he.getLife_turn() > 0) {
			detail += he.getLife_turn() + "转";
		}
		detail += he.getLevel() + "级";

		detail += "\n[门派]:" + he.getFamily().getName();

		detail += "\n[称号]:";
		MmochatChenHao chenhao = he.getCurChenHao();
		if (chenhao == null) {
			detail += "-";
		} else {
			detail += chenhao.getName();
		}

		if (me
				.getOtherSystemSettingByType(MmochatOtherSystemSettingType.允许编辑心情)) {
			detail += "\n[心情]:"
					+ MmochatUtil.wrapColor(he.getMoodInfo(), Color.magenta);
		} else {
			detail += "\n[客服处理记录]:"
					+ MmochatUtil.wrapColor(he.getMoodInfo(), Color.yellow);
		}

		if (!he.hasGang()) {
			detail += "\n[帮派]:-";
		} else {
			MmochatGang gang = MmochatGangService.getGangById(he.getGangId());
			if (gang == null) {
				detail += "\n[帮派]:-";
			} else {
				String gangName = gang.getName();
				gangName = gangName.replaceAll("", "");
				gangName = gangName.replaceAll("", "");
				gangName = gangName.replaceAll("", "");
				gangName = gangName.replaceAll("", "");
				detail += "\n[帮派]:" + gangName;
			}
		}
		if (he.getTeacher_name() == null) {
			detail += "\n[师傅]:-";
		} else {
			detail += "\n[师傅]:" + he.getTeacher_name();
		}

		if (he.getWife_name() == null) {
			detail += "\n[配偶]:-";
		} else {
			detail += "\n[配偶]:" + he.getWife_name();
		}

		// 好友度
		int friendValue = 0;
		MmochatFriend friend = me.getMyDearFriends().get(he.getRoleId());
		if (friend != null) {
			friendValue = friend.getFriendValue();
		}
		detail += "\n[好友度]:" + friendValue;

		tlv.setContent(new Text(detail));

		if (me.getRoleId() == he.getRoleId()) {
			tlv.setLeftName("编辑");
			CreateEditBoxTLV edit = new CreateEditBoxTLV();
			edit.setTitle("请编辑您的心情(35字内)");
			edit.setLeftName("编辑");
			edit.setRightName("取消");
			edit.setContentLenMax(35);
			edit.setBoxType(CreateEditBoxTLV.TYPE_MSGBOX);
			edit.setInputType(CreateEditBoxTLV.INPUT_ANY << 4);
			edit.addLeftTLV(new ClearDataTLV());
			edit.addLeftTLV(new AddEditBoxTLV());
			edit.addLeftTLV(new SendDataTLV(
					MmochatConstant.getClientModuleId(), MmochatMain
							.getModuleInstID(),
					MmochatConstant.MSGCODE_MMOCHAT_C_6_25, (int) me
							.getRoleId()));
			ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
			edit.addLeftTLV(wait);
			tlv.addLeftTLV(edit);
		} else {
			tlv.setLeftName("菜单");
			ShowPopupMenuTLV menu = new ShowPopupMenuTLV();
			menu.addItemEvent("远程交易", new ClearDataTLV(), new AddDataTLV(
					(int) me.getRoleId()), new SendDataTLV(MmochatConstant
					.getClientModuleId(), MmochatMain.getModuleInstID(),
					MmochatConstant.MSGCODE_MMOCHAT_C_7_23, (int) he
							.getRoleId()), new ShowWaitingMsgBoxTLV());

			menu.addItemEvent("查看装备", new ClearDataTLV(), new AddDataTLV(
					(int) me.getRoleId()), new SendDataTLV(MmochatConstant
					.getClientModuleId(), MmochatMain.getModuleInstID(),
					MmochatConstant.MSGCODE_MMOCHAT_C_6_18, (int) he
							.getRoleId()), new ShowWaitingMsgBoxTLV());

			menu.addItemEvent("加为好友", new ClearDataTLV(), new AddDataTLV(
					(int) he.getRoleId()),
					new AddDataTLV((int) me.getRoleId()), new SendDataTLV(
							MmochatConstant.getClientModuleId(), MmochatMain
									.getModuleInstID(),
							MmochatConstant.MSGCODE_MMOCHAT_C_6_1, (int) 5),
					new ShowWaitingMsgBoxTLV());

			menu.addItemEvent("禁言10分钟", new ClearDataTLV(), new AddDataTLV(
					(int) he.getRoleId()), new SendDataTLV(MmochatConstant
					.getClientModuleId(), MmochatMain.getModuleInstID(),
					MmochatConstant.MSGCODE_MMOCHAT_C_6_26, (int) me
							.getRoleId()), new ShowWaitingMsgBoxTLV());

			tlv.addLeftTLV(menu);
		}
		return tlv;
	}

	// 6.1 点击玩家执行操作
	@SuppressWarnings("deprecation")
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_1(SkymobiHandler handler,
			Mmochat_6_1C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}

		MmochatPlayer he = MmochatMainService.players
				.get(req.getTargetRoleId());
		if (he == null) {
			return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
					"该玩家当前不在线!", MmochatConstant.TLV_WIN_CLICKROLE);
		}
		MmochatMap curMap = MmochatMapService.getMapByMapId(me.getMapId());
		if (curMap == null) {
			return null;
		}
		switch (req.getIndex()) {
		case 0: {
			// 在遇怪地图切磋则是进行强制PK
			if (curMap.isWalkToBattle()) {
				Date now = new Date();
				if (now.getHours() == 21 || now.getHours() == 22) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "21:00-23:00期间禁止野外杀人!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}

				List<MmochatPlayer> requestList = new ArrayList<MmochatPlayer>();
				if (me.isInTeam()) {
					MmochatTeam team = MmochatTeamService.teams.get(me
							.getTeamId());
					if (team == null) {
						me.leaveTeam();
						requestList.add(me);
					} else {
						for (Integer roleId : team.getMemberId().values()) {
							MmochatPlayer member = MmochatMainService.players
									.get(roleId);
							if (member != null) {
								requestList.add(member);
							}
						}
					}
				} else {
					requestList.add(me);
				}

				List<MmochatPlayer> targetList = new ArrayList<MmochatPlayer>();
				if (he.isInTeam()) {
					MmochatTeam team = MmochatTeamService.teams.get(he
							.getTeamId());
					if (team == null) {
						he.leaveTeam();
						targetList.add(he);
					} else {
						for (Integer roleId : team.getMemberId().values()) {
							MmochatPlayer member = MmochatMainService.players
									.get(roleId);
							if (member != null) {
								targetList.add(member);
							}
						}
					}
				} else {
					targetList.add(he);
				}

				int hisTeamNum = targetList.size();
				int maxTimes = 0;
				for (MmochatPlayer member : requestList) {
					MmochatDailyActivity activity;
					Date lastDate; // 上次参加活动日期
					activity = member.getDailyActivities().get(
							MmochatDailyActivityType.杀人);
					int times = 0;
					if (activity == null) {
						// 第一次参加此活动
						times = 0;
					} else {
						lastDate = new Date(activity.getLastTime());
						if (now.getDate() == lastDate.getDate()
								&& now.getMonth() == lastDate.getMonth()
								&& now.getYear() == lastDate.getYear()) {
							// 今天参加过此活动
							if (activity.getDailyTimes() >= activity.getType()
									.getMaxDailyTimes()) {
								return MmochatUtil.closeWindowAndShowMsgbox(req
										.getHallState(), MmochatUtil.wrapColor(
										member.getName(), Color.green)
										+ "今天已经杀了"
										+ activity.getType().getMaxDailyTimes()
										+ "次人，达到每天杀人次数上限!",
										MmochatConstant.TLV_WIN_CLICKROLE);
							} else {
								times = activity.getDailyTimes();
							}
						} else {
							// 今天没有参加过此活动
							times = 0;
						}
					}
					maxTimes = Math.max(maxTimes, times);
				}
				maxTimes++;
				int sn = MmochatConstant.moneyCostToKillPerson + 50000
						* maxTimes * (maxTimes - 1) / 2;
				sn = Math.max(sn, MmochatConstant.moneyCostToKillPerson);

				String msg = "您确定要击杀"
						+ MmochatUtil.wrapColor(he.getName(), Color.green)
						+ "么?"
						+ MmochatUtil.wrapColor("野外杀人时死亡会受到死亡惩罚!这是您今天第"
								+ maxTimes + "次(组队时，以队伍中最高杀人次数计)杀人，" + "需消耗"
								+ MmochatUtil.getColorMoney(sn * hisTeamNum)
								+ "文钱(对方" + hisTeamNum + "人，每人" + sn + "文)!",
								Color.red);
				CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
				msgbox.setContent(new Text(msg));
				msgbox.setLeftName("杀戮");
				msgbox.setRightName("取消");
				msgbox.addLeftTLV(new ClearDataTLV());
				msgbox.addLeftTLV(new AddDataTLV((int) me.getRoleId()));
				msgbox.addLeftTLV(new SendDataTLV(MmochatConstant
						.getClientModuleId(), MmochatMain.getModuleInstID(),
						MmochatConstant.MSGCODE_MMOCHAT_C_6_19, (int) he
								.getRoleId()));
				ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
				wait.setShowCancel(false);
				msgbox.addLeftTLV(wait);
				return MmochatUtil.tlvResponse(req.getHallState(),
						new CloseWinTLV(MmochatConstant.TLV_WIN_CLICKROLE),
						msgbox);
			}

			if (curMap.getMapId() == MmochatConstant.mapId_比武场) {
				// 比武场
				if (MmochatTeamService.getTeamState(me) == MmochatTeamStateType.队员) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "组队中只有队长才能发起比武!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (!me.isInSameMapLine(he)) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "该玩家已经离开!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (!me.isFreeState()) {
					return null;
				}
				if (MmochatMapService.isInZhangJiPkRange(me)) {
					// 我在场内
					MmochatPlayer hisTeamLeader = null;
					List<MmochatPlayer> targetList = new ArrayList<MmochatPlayer>();
					if (he.isInTeam()) {
						MmochatTeam team = MmochatTeamService.teams.get(he
								.getTeamId());
						if (team == null) {
							hisTeamLeader = he;
							he.leaveTeam();
							targetList.add(he);
						} else {
							for (Integer roleId : team.getMemberId().values()) {
								MmochatPlayer member = MmochatMainService.players
										.get(roleId);
								if (member != null) {
									targetList.add(member);
									if (team.isTeamLeader(roleId)) {
										hisTeamLeader = member;
									}
								}
							}
						}
					} else {
						hisTeamLeader = he;
						targetList.add(he);
					}
					if (hisTeamLeader == null) {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "对方队伍的队长掉线,暂时无法发起比武。",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
					if (hisTeamLeader.isInBattle()) {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "对方现在战斗中，暂时无法进行比武!",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
					if (!hisTeamLeader.isFreeState()) {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "对方忙，暂时无法进行比武!",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
					if (MmochatMapService.isInZhangJiPkRange(hisTeamLeader)) {
						// 对方队长也在场内
						List<MmochatPlayer> requestList = new ArrayList<MmochatPlayer>();
						if (me.isInTeam()) {
							MmochatTeam team = MmochatTeamService.teams.get(me
									.getTeamId());
							if (team == null) {
								me.leaveTeam();
								requestList.add(me);
							} else {
								for (Integer roleId : team.getMemberId()
										.values()) {
									MmochatPlayer member = MmochatMainService.players
											.get(roleId);
									if (member != null) {
										requestList.add(member);
									}
								}
							}
						} else {
							requestList.add(me);
						}

						if (requestList.contains(he) || targetList.contains(me)) {
							return MmochatUtil.closeWindowAndShowMsgbox(req
									.getHallState(), "不能与队友比武!",
									MmochatConstant.TLV_WIN_CLICKROLE);
						}

						for (MmochatPlayer role : requestList) {
							if (!role.isAcceptZhanjiPk()) {
								if (role.getId() == me.getId()) {
									return MmochatUtil
											.closeWindowAndShowMsgbox(
													req.getHallState(),
													"您设置了拒绝比武,请按左软键进入切磋比武设置,开启比武。",
													MmochatConstant.TLV_WIN_CLICKROLE);
								} else {
									MmochatChatService.sendSystemMsgToPerson(
											role,
											"您设置了拒绝比武,请按左软键进入切磋比武设置,开启比武。");
									return MmochatUtil
											.closeWindowAndShowMsgbox(
													req.getHallState(),
													role.getName() + "设置了拒绝比武。",
													MmochatConstant.TLV_WIN_CLICKROLE);
								}
							}
							if (role.getZhanji() < MmochatConstant.minZhangJiNeedInPkMap) {
								if (role.getId() == me.getId()) {
									return MmochatUtil
											.closeWindowAndShowMsgbox(
													req.getHallState(),
													"您的战绩不足"
															+ MmochatConstant.minZhangJiNeedInPkMap
															+ ",无法比武。",
													MmochatConstant.TLV_WIN_CLICKROLE);
								} else {
									MmochatChatService
											.sendSystemMsgToPerson(
													role,
													"您的战绩不足"
															+ MmochatConstant.minZhangJiNeedInPkMap
															+ ",无法比武。");
									return MmochatUtil
											.closeWindowAndShowMsgbox(
													req.getHallState(),
													role.getName()
															+ "的战绩不足"
															+ MmochatConstant.minZhangJiNeedInPkMap
															+ ",无法比武。",
													MmochatConstant.TLV_WIN_CLICKROLE);
								}
							}
						}
						String teamInfoHead = "";
						if (he.isInTeam()) {
							teamInfoHead = "对方队伍里的";
						}
						for (MmochatPlayer role : targetList) {
							if (!role.isAcceptZhanjiPk()) {
								return MmochatUtil.closeWindowAndShowMsgbox(req
										.getHallState(), teamInfoHead
										+ role.getName() + "设置了拒绝比武。",
										MmochatConstant.TLV_WIN_CLICKROLE);
							}
							if (role.getZhanji() < MmochatConstant.minZhangJiNeedInPkMap) {
								return MmochatUtil.closeWindowAndShowMsgbox(req
										.getHallState(), teamInfoHead
										+ role.getName() + "战绩不足，无法比武。",
										MmochatConstant.TLV_WIN_CLICKROLE);
							}
						}

						// 发出比武请求
						String msg = MmochatUtil.wrapColor(me.getName(),
								Color.green)
								+ "请求与你比武!";
						CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
						msgbox.setContent(new Text(msg));
						msgbox.setLeftName("查看");
						msgbox.addLeftTLV(new ClearDataTLV());
						msgbox.addLeftTLV(new AddDataTLV((int) hisTeamLeader
								.getRoleId())); // 我的roleId
						msgbox.addLeftTLV(new AddDataTLV((int) me.getRoleId())); // 请求比武方的roleId
						msgbox
								.addLeftTLV(new SendDataTLV(MmochatConstant
										.getClientModuleId(), MmochatMain
										.getModuleInstID(),
										MmochatConstant.MSGCODE_MMOCHAT_C_6_14,
										(int) 0));
						ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
						wait.setShowCancel(false);
						msgbox.addLeftTLV(wait);

						msgbox.setRightName("拒绝");
						msgbox.addRightTLV(new ClearDataTLV());
						msgbox.addRightTLV(new AddDataTLV((int) hisTeamLeader
								.getRoleId())); // 我的roleId
						msgbox
								.addRightTLV(new AddDataTLV((int) me
										.getRoleId())); // 请求比武方的roleId
						msgbox
								.addRightTLV(new SendDataTLV(MmochatConstant
										.getClientModuleId(), MmochatMain
										.getModuleInstID(),
										MmochatConstant.MSGCODE_MMOCHAT_C_6_14,
										(int) 1));

						CtrlTLVStructureRequest pack = new CtrlTLVStructureRequest(
								0, msgbox);
						pack.setSrcId(MmochatMain.getModuleInstID());
						pack.setDstId(MmochatConstant.getClientModuleId());
						pack
								.setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_20);
						MmochatUtil.sendCommonPack(hisTeamLeader, pack);

						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "比武请求已发出。",
								MmochatConstant.TLV_WIN_CLICKROLE);
					} else {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "对方尚未进入比武区域，无法切磋。",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
				} else {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(),
							"您尚未进入比武区域，无法切磋。(比武区域是由草坪围起来的方形中央区域)",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
			} else if (curMap.getMapId() == MmochatConstant.mapId_跨服擂台) {
				// 跨服擂台
				if (MmochatTeamService.getTeamState(me) == MmochatTeamStateType.队员) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "组队中只有队长才能发起比武!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (!me.isInSameMapLine(he)) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "该玩家已经离开!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (!me.isFreeState()) {
					return null;
				}
				if (MmochatMapService.isInZhangJiPkRange(me)) {
					// 我在场内
					MmochatPlayer hisTeamLeader = null;
					List<MmochatPlayer> targetList = new ArrayList<MmochatPlayer>();
					if (he.isInTeam()) {
						MmochatTeam team = MmochatTeamService.teams.get(he
								.getTeamId());
						if (team == null) {
							hisTeamLeader = he;
							he.leaveTeam();
							targetList.add(he);
						} else {
							for (Integer roleId : team.getMemberId().values()) {
								MmochatPlayer member = MmochatMainService.players
										.get(roleId);
								if (member != null) {
									targetList.add(member);
									if (team.isTeamLeader(roleId)) {
										hisTeamLeader = member;
									}
								}
							}
						}
					} else {
						hisTeamLeader = he;
						targetList.add(he);
					}
					if (hisTeamLeader == null) {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "对方队伍的队长掉线,暂时无法发起比武。",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
					if (hisTeamLeader.isInBattle()) {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "对方现在战斗中，暂时无法进行比武!",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
					if (!hisTeamLeader.isFreeState()) {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "对方忙，暂时无法进行比武!",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
					if (MmochatMapService.isInZhangJiPkRange(hisTeamLeader)) {
						// 对方队长也在场内
						List<MmochatPlayer> requestList = new ArrayList<MmochatPlayer>();
						if (me.isInTeam()) {
							MmochatTeam team = MmochatTeamService.teams.get(me
									.getTeamId());
							if (team == null) {
								me.leaveTeam();
								requestList.add(me);
							} else {
								for (Integer roleId : team.getMemberId()
										.values()) {
									MmochatPlayer member = MmochatMainService.players
											.get(roleId);
									if (member != null) {
										requestList.add(member);
									}
								}
							}
						} else {
							requestList.add(me);
						}

						if (requestList.contains(he) || targetList.contains(me)) {
							return MmochatUtil.closeWindowAndShowMsgbox(req
									.getHallState(), "不能与队友比武!",
									MmochatConstant.TLV_WIN_CLICKROLE);
						}

						for (MmochatPlayer role : requestList) {
							if (role.getPk_score() < MmochatConstant.minPkScoreNeed) {
								if (role.getId() == me.getId()) {
									return MmochatUtil
											.closeWindowAndShowMsgbox(
													req.getHallState(),
													"您的竞技点不足"
															+ MmochatConstant.minPkScoreNeed
															+ ",请退出回到原区服!在原区服内在线每分钟可恢复"
															+ MmochatConstant.addPkScorePerUnit
															+ "个竞技点!",
													MmochatConstant.TLV_WIN_CLICKROLE);
								} else {
									MmochatChatService
											.sendSystemMsgToPerson(
													role,
													"您的竞技点不足"
															+ MmochatConstant.minPkScoreNeed
															+ ",请退出回到原区服!在原区服内在线每分钟可恢复"
															+ MmochatConstant.addPkScorePerUnit
															+ "个竞技点!");
									return MmochatUtil
											.closeWindowAndShowMsgbox(
													req.getHallState(),
													role.getName()
															+ "的竞技点不足"
															+ MmochatConstant.minPkScoreNeed
															+ ",无法比武。",
													MmochatConstant.TLV_WIN_CLICKROLE);
								}
							}
						}
						String teamInfoHead = "";
						if (he.isInTeam()) {
							teamInfoHead = "对方队伍里的";
						}
						for (MmochatPlayer role : targetList) {
							if (role.getPk_score() < MmochatConstant.minPkScoreNeed) {
								return MmochatUtil.closeWindowAndShowMsgbox(req
										.getHallState(), teamInfoHead
										+ role.getName() + "竞技点不足，无法比武。",
										MmochatConstant.TLV_WIN_CLICKROLE);
							}
						}

						// 发出比武请求
						String msg = MmochatUtil.wrapColor(me.getName(),
								Color.green)
								+ "请求与你比武!";
						CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
						msgbox.setContent(new Text(msg));
						msgbox.setLeftName("查看");
						msgbox.addLeftTLV(new ClearDataTLV());
						msgbox.addLeftTLV(new AddDataTLV((int) hisTeamLeader
								.getRoleId())); // 我的roleId
						msgbox.addLeftTLV(new AddDataTLV((int) me.getRoleId())); // 请求比武方的roleId
						msgbox
								.addLeftTLV(new SendDataTLV(MmochatConstant
										.getClientModuleId(), MmochatMain
										.getModuleInstID(),
										MmochatConstant.MSGCODE_MMOCHAT_C_6_14,
										(int) 0));
						ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
						wait.setShowCancel(false);
						msgbox.addLeftTLV(wait);

						msgbox.setRightName("拒绝");
						msgbox.addRightTLV(new ClearDataTLV());
						msgbox.addRightTLV(new AddDataTLV((int) hisTeamLeader
								.getRoleId())); // 我的roleId
						msgbox
								.addRightTLV(new AddDataTLV((int) me
										.getRoleId())); // 请求比武方的roleId
						msgbox
								.addRightTLV(new SendDataTLV(MmochatConstant
										.getClientModuleId(), MmochatMain
										.getModuleInstID(),
										MmochatConstant.MSGCODE_MMOCHAT_C_6_14,
										(int) 1));

						CtrlTLVStructureRequest pack = new CtrlTLVStructureRequest(
								0, msgbox);
						pack.setSrcId(MmochatMain.getModuleInstID());
						pack.setDstId(MmochatConstant.getClientModuleId());
						pack
								.setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_20);
						MmochatUtil.sendCommonPack(hisTeamLeader, pack);

						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "比武请求已发出。",
								MmochatConstant.TLV_WIN_CLICKROLE);
					} else {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "对方尚未进入比武区域，无法切磋。",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
				} else {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(),
							"您尚未进入比武区域，无法切磋。(比武区域是由草坪围起来的方形中央区域)",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}

			} else {
				// 切磋
				if (!curMap.isCanFriendlyPk()) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "本地图不允许切磋!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (MmochatTeamService.getTeamState(me) == MmochatTeamStateType.队员) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "组队中只有队长才能发起切磋!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (!me.isAcceptFriendlyPk()) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "您设置了拒绝切磋,请按左软键进入切磋比武设置,开启切磋。",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (!me.canFriendlyFight()) {
					return null;
				}
				if (!me.isInSameMapLine(he)) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "该玩家已经离开!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (!me.isFreeState()) {
					return null;
				}

				// 如果是组队状态,需要将所有队员加入列表
				MmochatPlayer hisTeamLeader = null;
				List<MmochatPlayer> targetList = new ArrayList<MmochatPlayer>();
				if (he.isInTeam()) {
					MmochatTeam team = MmochatTeamService.teams.get(he
							.getTeamId());
					if (team == null) {
						hisTeamLeader = he;
						he.leaveTeam();
						targetList.add(he);
					} else {
						for (Integer roleId : team.getMemberId().values()) {
							MmochatPlayer member = MmochatMainService
									.getRoleFromBuffer(roleId);
							if (member != null) {
								targetList.add(member);
								if (team.isTeamLeader(roleId)) {
									hisTeamLeader = member;
								}
							}
						}
					}
				} else {
					hisTeamLeader = he;
					targetList.add(he);
				}
				if (hisTeamLeader == null) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "对方队伍的队长掉线,暂时无法发起切磋。",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (!hisTeamLeader.isFreeState()) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "对方忙，暂时无法进行切磋!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (!hisTeamLeader.isAcceptFriendlyPk()) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "对方设置了拒绝切磋。",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (!hisTeamLeader.canFriendlyFight()) {
					// TODO:进入观战
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "对方正在战斗中或交易中,无法进行切磋!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (hisTeamLeader.getMapId() != me.getMapId()
						|| hisTeamLeader.getLine() != me.getLine()) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "对方已经离开!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}

				// 如果是组队状态,需要将所有队员加入列表
				List<MmochatPlayer> requestList = new ArrayList<MmochatPlayer>();
				if (me.isInTeam()) {
					MmochatTeam team = MmochatTeamService.teams.get(me
							.getTeamId());
					if (team == null) {
						me.leaveTeam();
						requestList.add(me);
					} else {
						for (Integer roleId : team.getMemberId().values()) {
							MmochatPlayer member = MmochatMainService
									.getRoleFromBuffer(roleId);
							if (member != null) {
								requestList.add(member);
							}
						}
					}
				} else {
					requestList.add(me);
				}

				if (requestList.contains(he) || targetList.contains(me)) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "不能与队友切磋!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				// 进入战斗
				MmochatBattleService.enterPVPBattle(me.getMapId(), (byte) me
						.getLine(), requestList, targetList,
						MmochatBattleType.友好切磋);
			}
			break;
		}
		case 1: {
			// 加入队伍
			// 如果我是队长，则为邀请操作
			// 如果我没在队中，则为申请操作
			if (!me.isInSameMapLine(he)) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"该玩家已经离开!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (!me.isInTeam()) {
				// 判断是否为队长, 队伍是否已满, 是否在战斗中等是否处于接受组队状态
				if (!he.isInTeam()) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "对方不在队伍中!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (me.isInTeam()) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "您已经在队伍中了!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				switch (curMap.getTeamCondition()) {
				case 任意组队:
					break;
				case 只允许同帮派组队:
					if (me.getGangId() != he.getGangId()) {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "您和对方不是同一帮派，不允许组队!",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
					break;
				case 只允许同战队组队:
					if (me.getPkteam_id() != he.getPkteam_id()) {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "您和对方不是同一战队，不允许组队!",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
					break;
				case 只允许同区服组队:
					if (me.getRegServerInstId() != he.getRegServerInstId()) {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "您和对方不在同一个区服，不允许组队!",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
					break;
				case 不允许组队:
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "本地图不允许组队!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				default:
					break;
				}
				MmochatTeam team = MmochatTeamService.teams.get(he.getTeamId());
				if (team == null) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "对方不在队伍中!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				int ret = team.addRequest(me.getRoleId());
				if (ret == 1) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "队伍人数已满，申请失败!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (ret == 2) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "申请加入对方队伍的人数过多，申请失败!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				// 给队长下发通知, 队伍图标闪动
				MmochatPlayer leader = MmochatMainService.players.get(team
						.getTeamLeaderRoleId());
				if (leader != null) {
					Mmochat_8_10S pack = new Mmochat_8_10S();
					MmochatUtil.sendCommonPack(leader, pack);
				}
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"入队申请已发出!", MmochatConstant.TLV_WIN_CLICKROLE);
			} else if (MmochatTeamService.getTeamState(me) == MmochatTeamStateType.队长) {
				// 我是队长，如果对方没有组队，则发出组队邀请
				if (he.isInTeam()) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "对方已经有队伍了!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				switch (curMap.getTeamCondition()) {
				case 任意组队:
					break;
				case 只允许同帮派组队:
					if (me.getGangId() != he.getGangId()) {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "您和对方不是同一帮派，不允许邀请对方!",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
					break;
				case 只允许同战队组队:
					if (me.getPkteam_id() != he.getPkteam_id()) {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "您和对方不是同一战队，不允许邀请对方!",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
					break;
				case 只允许同区服组队:
					if (me.getRegServerInstId() != he.getRegServerInstId()) {
						return MmochatUtil.closeWindowAndShowMsgbox(req
								.getHallState(), "您和对方不在同一个区服，不允许组队!",
								MmochatConstant.TLV_WIN_CLICKROLE);
					}
					break;
				case 不允许组队:
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "本地图不允许组队!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				default:
					break;
				}
				MmochatTeam team = MmochatTeamService.teams.get(me.getTeamId());
				if (team == null) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "您不在队伍中，无法邀请对方!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
				if (team.isFull()) {
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "队伍人数已满，无法邀请对方!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}

				// 给对方下发邀请, 队伍图标闪动
				String msg = MmochatUtil.wrapColor(me.getName(), Color.green)
						+ "(" + me.getLevel() + "级)" + "邀请您加入队伍!";
				CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
				msgbox.setContent(new Text(msg));
				msgbox.setLeftName("同意");
				msgbox.setRightName("拒绝");

				msgbox.addLeftTLV(new ClearDataTLV());
				msgbox.addLeftTLV(new AddDataTLV((int) me.getRoleId())); // 队长roleId
				msgbox.addLeftTLV(new AddDataTLV((int) he.getRoleId())); // 被邀方roleId
				msgbox.addLeftTLV(new SendDataTLV(MmochatConstant
						.getClientModuleId(), MmochatMain.getModuleInstID(),
						MmochatConstant.MSGCODE_MMOCHAT_C_8_11, (int) 0));// 0：同意

				msgbox.addRightTLV(new ClearDataTLV());
				msgbox.addRightTLV(new AddDataTLV((int) me.getRoleId()));
				msgbox.addRightTLV(new AddDataTLV((int) he.getRoleId()));
				msgbox.addRightTLV(new SendDataTLV(MmochatConstant
						.getClientModuleId(), MmochatMain.getModuleInstID(),
						MmochatConstant.MSGCODE_MMOCHAT_C_8_11, (int) 1));// 1：拒绝

				CtrlTLVStructureRequest pack = new CtrlTLVStructureRequest(0,
						msgbox);
				pack.setSrcId(MmochatMain.getModuleInstID());
				pack.setDstId(MmochatConstant.getClientModuleId());
				pack.setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_20);
				MmochatUtil.sendCommonPack(he, pack);

				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"入队邀请已发出!", MmochatConstant.TLV_WIN_CLICKROLE);

			}
		}
		case 2: {
			// 交易
			// if (!me.isInSameScreen(he)) {
			// return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
			// "该玩家已经离开!", MmochatConstant.TLV_WIN_CLICKROLE);
			// }
			if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"跨服区内无法进行此操作!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (!me.canDeal()) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"您目前无法进行交易!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (he.isInDeal()) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"对方正在交易中,暂时无法与您交易!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (!he.canDeal()) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"对方目前无法进行交易!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (!me.isFreeState()) {
				return null;
			}
			if (!he.isFreeState()) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"对方忙，暂时无法交易!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			try {
				if (!he
						.getOtherSystemSettingByType(MmochatOtherSystemSettingType.近程交易)) {
					MmochatChatService.sendSystemMsgToPerson(he, MmochatUtil
							.wrapColor(me.getName(), Color.green)
							+ "尝试与您交易，但您设置了拒绝近程交易，无法交易!");
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "对方拒绝近距离交易!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			me.requestDeal(he);
			break;
		}
		case 3: {
			// 入帮
			if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"跨服区内无法进行此操作!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (!he.hasGang()) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"对方没有加入帮派,无法申请加入其帮派!",
						MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (me.hasGang()) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"您已经加入一个帮派了，无法再入其它帮派!",
						MmochatConstant.TLV_WIN_CLICKROLE);
			}
			MmochatGang hisGang = MmochatGangService
					.getGangById(he.getGangId());
			if (hisGang == null) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"对方没有加入帮派,无法申请加入其帮派!",
						MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (hisGang.getRequesters().containsKey(me.getRoleId())) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"您已经在对方帮派的申请列表中了，请耐心等待帮派管理人的处理!",
						MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (hisGang.isRequestFull()) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"申请加入对方帮派的人数过多，暂时不接受新的申请!",
						MmochatConstant.TLV_WIN_CLICKROLE);
			}
			MmochatGangRequester newRequest = new MmochatGangRequester();
			newRequest.setRoleId(me.getRoleId());
			newRequest.setBmpId(me.getBmpId());
			newRequest.setName(me.getName());
			newRequest.setLevel(me.getLevel());
			hisGang.getRequesters().put(me.getRoleId(), newRequest);

			// 向帮派管理员下发闪动提示
			for (MmochatGangMember myInfo : hisGang.getMembers().values()) {
				if (myInfo.getType() == MmochatGangMemberType.帮主
						|| myInfo.getType() == MmochatGangMemberType.副帮) {
					MmochatPlayer member = MmochatMainService.players
							.get(myInfo.getRoleId());
					if (member != null) {
						Mmochat_4_8S pack = new Mmochat_4_8S();
						pack.setHintKey(MmochatConstant.MR_KEY_8);
						pack.setFlashTimes(6);
						MmochatUtil.sendCommonPack(member, pack);
					}
				}
			}

			return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
					"申请已发出，请耐心等待帮派管理人的处理!", MmochatConstant.TLV_WIN_CLICKROLE);
		}
		case 4:
			// 查看
			CreateTlvWin tlv = getUserInfoTlv(me, he);
			return MmochatUtil.tlvResponse(req.getHallState(), tlv);
		case 5:
			// 加为好友
			if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"跨服区内无法进行此操作!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			return MmochatFriendService
					.addNewFriend(req.getHallState(), me, he);
		case 6: {
			// 观战
			if (!curMap.isCanWatchPk()) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"本地图不允许观战!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (MmochatTeamService.getTeamState(me) == MmochatTeamStateType.队员) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"组队中只有队长才能带队观战!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (!me.canWatchPk()) {
				return null;
			}
			if (!me.isCanEnterBattle()) {
				return null;
			}
			if (!me.isInSameMapLine(he)) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"该玩家已经离开!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (!he.isInBattle()) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"对方不在战斗中!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (!me.isFreeState()) {
				return null;
			}
			MmochatBattle battle = MmochatBattleService.battles.get(he
					.getBattleId());
			if (battle == null || battle.isOver()) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"对方不在战斗中!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (battle.getAudiences().size() >= MmochatConstant.maxAudiencesPerBattle) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"观战人数已达上限!", MmochatConstant.TLV_WIN_CLICKROLE);
			}

			// 加入观战列表
			List<MmochatPlayer> watchList = new ArrayList<MmochatPlayer>();
			if (me.isInTeam()) {
				MmochatTeam team1 = MmochatTeamService.teams
						.get(me.getTeamId());
				if (team1 == null) {
					me.leaveTeam();
					watchList.add(me);
				} else {
					for (Integer roleId : team1.getMemberId().values()) {
						MmochatPlayer member = MmochatMainService.players
								.get(roleId);
						if (member != null) {
							watchList.add(member);
						}
					}
				}
			} else {
				watchList.add(me);
			}
			for (MmochatPlayer role : watchList) {
				role.stopDeal();
				if (role.lockState(MmochatRoleStateType.进入观战时)) {
					battle.addAudience(role);
				} else {
					log.debug(role.getName() + "当前状态为:"
							+ role.getState().toString() + ",无法进入观战");
				}
			}

			// 下发3.1协议
			Byte pos = battle.getPos(he);
			for (MmochatPlayer role : watchList) {
				Mmochat_3_1S pack = new Mmochat_3_1S();
				pack.setBattle(battle);
				pack.setMapId(role.getMapId());
				pack.setLine((byte) role.getLine());
				pack.setMyPos((byte) pos);
				pack.setAudience(true);
				MmochatUtil.sendCommonPack(role, pack);
			}

			if (battle.isOver()) {
				// 刚进入观战，战斗就结束了，此时要手动脱离观战
				// 下发结束战斗协议，及恢复状态
				for (MmochatPlayer role : watchList) {
					if (role.getState() == MmochatRoleStateType.进入观战时) {
						MmochatBattle endBattle = new MmochatBattle();
						endBattle.setBattleId(battle.getBattleId());
						endBattle
								.setTurn(MmochatConstant.maxRoundPerBattle + 1);
						endBattle.setOver();
						Mmochat_3_3S pack = new Mmochat_3_3S();
						pack.setBattle(endBattle);
						MmochatUtil.sendCommonPack(role, pack);
						role.unLockState();
						role.leaveWatchingBattle();
					}
				}
			}
			break;
		}
		default:
			break;
		}
		return null;
	}

	// 6.2 查看自己的角色信息
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_2(SkymobiHandler handler,
			Mmochat_6_2C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return null;
		}

		Mmochat_6_2S pack = new Mmochat_6_2S();
		pack.setPlayer(me);
		return pack;
	}

	// 6.3 快捷操作
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_3(SkymobiHandler handler,
			Mmochat_6_3C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (req.getVersion() != MmochatConstant.quickStartVersion) {
			return MmochatUtil.msgbox(req.getHallState(), "您的版本过旧,请退出重新进入游戏!");
		}

		MmochatQickStartType type = MmochatQickStartType.get(req
				.getQuickStartValue());
		if (type == null) {
			return MmochatUtil.msgbox(req.getHallState(), "此功能暂未开放!");
		}

		// TODO
		switch (type) {
		case 全队换线: {
			// if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			// // 在其它服，不处理
			// return MmochatUtil.msgbox(req.getHallState(),
			// "当前位于跨服区，无法进行此操作!");
			// }

			MmochatMap curMap = MmochatMapService.getMapByMapId(me.getMapId());
			if (!curMap.isCanChangeLine()) {
				return MmochatUtil.msgbox(req.getHallState(), "本地图不允许换线!");
			}
			Integer[] linePlayerNum = new Integer[MmochatConstant.maxMapLineNum];
			Arrays.fill(linePlayerNum, 0);
			try {
				for (MmochatMap map : MmochatMapService.maps.values()) {
					if (map != null) {
						for (int i = 0; i < MmochatConstant.maxMapLineNum; i++) {
							linePlayerNum[i] += map.getLineRoleMap(i).size();
						}
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}

			CreateTlvWin tlv = new CreateTlvWin();
			tlv.setWinType(WinType.List);
			tlv.setLeftName("切换");
			tlv.setRightName("返回");
			tlv.setTitle(type.toString());
			tlv.setWinHeight(250);
			tlv.setWinId(MmochatConstant.TLV_WIN_LINELIST);
			tlv.addRightTLV(new CloseWinTLV(MmochatConstant.TLV_WIN_LINELIST));

			ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
			wait.setShowCancel(false);
			String lineName[] = new String[] { "一线", "二线", "三线", "四线", "五线",
					"六线", "七线", "八线", "九线", "十线", "十一线", "十二线", "十三线", "十四线",
					"十五线", "十六线", "十七线", "十八线", "十九线", "二十线" };
			for (int i = 0; i < MmochatConstant.maxMapLineNum; i++) {
				if (i == me.getLine()) {
					continue;
				}
				String item = lineName[i] + "("
						+ MmochatUtil.getLineHotType(linePlayerNum[i]) + ")";
				tlv.addItemEvent(item, new ClearDataTLV(), new AddDataTLV(
						(int) i));
			}
			tlv.addLeftTLV(new SendDataTLV(MmochatConstant.getClientModuleId(),
					MmochatMain.getModuleInstID(),
					MmochatConstant.MSGCODE_MMOCHAT_C_1_15, (int) req
							.getRoleId()));
			tlv.addLeftTLV(wait);
			return MmochatUtil.tlvResponse(req.getHallState(), tlv);
		}
		case 聊天频道设置: {
			CreateTlvWin tlv = getShowChatSetTlv(me);
			return MmochatUtil.tlvResponse(req.getHallState(), tlv);
		}
		case 切磋比武设置: {
			CreateTlvWin tlv = getPkSetTlv(me);
			return MmochatUtil.tlvResponse(req.getHallState(), tlv);
		}
		case 好友设置: {
			ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
			wait.setShowCancel(false);

			CreateTlvWin tlv = new CreateTlvWin();
			tlv.setWinType(WinType.List);
			tlv.setLeftName("切换");
			tlv.setRightName("返回");
			tlv.setTitle(type.toString());
			tlv.setWinHeight(250);
			tlv.setWinId(MmochatConstant.TLV_WIN_SET_FRIEND);
			tlv
					.addRightTLV(new CloseWinTLV(
							MmochatConstant.TLV_WIN_SET_FRIEND));
			String item = "拒绝陌生人消息";
			if (me.isAcceptStrangerMessage()) {
				item += MmochatUtil.wrapColor("\n未开启", Color.yellow);
			} else {
				item += MmochatUtil.wrapColor("\n已开启", Color.yellow);
			}
			tlv.addItemEvent(item, new ClearDataTLV(), new AddDataTLV((int) 0));

			item = "添加好友验证";
			if (me.isCheckAddMeFriend()) {
				item += MmochatUtil.wrapColor("\n已开启", Color.yellow);
			} else {
				item += MmochatUtil.wrapColor("\n未开启", Color.yellow);
			}
			tlv.addItemEvent(item, new ClearDataTLV(), new AddDataTLV((int) 1));

			item = "拒绝加为好友";
			if (me.isAcceptAddMeFriend()) {
				item += MmochatUtil.wrapColor("\n未开启", Color.yellow);
			} else {
				item += MmochatUtil.wrapColor("\n已开启", Color.yellow);
			}
			tlv.addItemEvent(item, new ClearDataTLV(), new AddDataTLV((int) 2));

			tlv.addLeftTLV(new SendDataTLV(MmochatConstant.getClientModuleId(),
					MmochatMain.getModuleInstID(),
					MmochatConstant.MSGCODE_MMOCHAT_C_10_19, (int) req
							.getRoleId()));
			tlv.addLeftTLV(wait);
			return MmochatUtil.tlvResponse(req.getHallState(), tlv);
		}
		case 自动遇怪: {
			MmochatMap curMap = MmochatMapService.getMapByMapId(me.getMapId());
			if (!curMap.isHasMonster()) {
				return MmochatUtil
						.msgbox(req.getHallState(), "此地图没有怪物，无法自动遇怪!");
			}
			Mmochat_6_8S pack = new Mmochat_6_8S();
			return pack;
		}
		case 查看道具状态: {
			if (me.getPropEffects().size() == 0) {
				return MmochatUtil.msgbox(req.getHallState(), "您当前没有道具状态!");
			}
			String content = "";
			String effectInfo;
			Date now = new Date();
			int index = 1;
			List<MmochatPropEffect> effectList = new ArrayList<MmochatPropEffect>(
					me.getPropEffects().values());
			Collections.sort(effectList);
			for (MmochatPropEffect effect : effectList) {
				effectInfo = MmochatUtil.wrapColor(index + "."
						+ effect.getPropType().getEffectInfo() + "\n",
						Color.yellow);
				if (effect.getPropType().getEffectType() == MmochatPropEffectType.时间) {
					long usedTime = now.getTime() - effect.getStartTime();
					long time = effect.getRestAmount() - usedTime;
					if (time <= 0) {
						continue;
					}
					effectInfo += MmochatUtil.wrapColor(MmochatUtil
							.getTimeString(time), Color.green);
				} else if (effect.getPropType().getEffectType() == MmochatPropEffectType.计量) {
					if (effect.getRestAmount() < 0) {
						continue;
					}
					effectInfo += MmochatUtil.wrapColor(effect.getRestAmount(),
							Color.green);
				}
				content += effectInfo + "\n";
				index++;
			}

			CreateTlvWin tlv = new CreateTlvWin();
			tlv.setWinType(WinType.Text);
			tlv.setRightName("返回");
			tlv.setTitle(type.toString());
			tlv.setWinHeight(250);
			tlv.setContent(new Text(content));
			tlv.addRightTLV(new CloseWinTLV());
			return MmochatUtil.tlvResponse(req.getHallState(), tlv);
		}
		case 同屏人数限制: {
			CreateTlvWin tlv = new CreateTlvWin();
			tlv.setWinType(WinType.Text);
			tlv.setTitle("同屏人数限制");
			tlv.setRightName("返回");
			tlv.setLeftName("设置");
			tlv.setWinHeight(250);
			tlv.setWinId(MmochatConstant.TLV_WIN_SET_SCREEN_ROLE_NUM);
			tlv.addRightTLV(new CloseWinTLV(
					MmochatConstant.TLV_WIN_SET_SCREEN_ROLE_NUM));

			String msg = MmochatUtil.wrapColor("当前同屏人数上限:"
					+ me.getMax_screen_role_num() + "人", Color.yellow);
			msg += "\n\n";
			msg += MmochatUtil.wrapColor("  同屏人数是指一个屏幕内最多看到的其它玩家人数。同屏人数设置越高，"
					+ "游戏越不流畅，但您能看到的玩家就越多，而且增加同屏人数，并不会增加流量负担。"
					+ "所以建议保证流畅的前提下，尽可能高得设置同屏人数，以获得最好的游戏体验。"
					+ "\n\n  建议设置范围：10人~50人", Color.green);

			CreateEditBoxTLV edit = new CreateEditBoxTLV();
			edit.setTitle("请输入同屏人数上限");
			edit.setLeftName("确定");
			edit.setRightName("取消");
			edit.setContentLenMax(2);
			edit.setBoxType(CreateEditBoxTLV.TYPE_MSGBOX);
			edit.setInputType(CreateEditBoxTLV.INPUT_NUM << 4);
			edit.addLeftTLV(new AddDataTLV((int) me.getRoleId()));
			edit.addLeftTLV(new AddEditBoxTLV());
			edit.addLeftTLV(new SendDataTLV(
					MmochatConstant.getClientModuleId(), MmochatMain
							.getModuleInstID(),
					MmochatConstant.MSGCODE_MMOCHAT_C_6_16, null));
			ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
			wait.setShowCancel(false);
			edit.addLeftTLV(wait);
			tlv.addLeftTLV(edit);

			tlv.setContent(new Text(msg));
			return MmochatUtil.tlvResponse(req.getHallState(), tlv);
		}
		case 其它系统设置: {
			CreateTlvWin tlv = getOtherSystemSetTlv(me);
			return MmochatUtil.tlvResponse(req.getHallState(), tlv);
		}
		case 查找在线玩家: {
			if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
				// 在其它服，不处理
				return MmochatUtil.msgbox(req.getHallState(),
						"当前位于跨服区，无法进行此操作!");
			}
			CreateTlvWin tlv = new CreateTlvWin();
			tlv.setWinType(WinType.List);
			tlv.setTitle("查找在线玩家");
			tlv.setRightName("返回");
			tlv.setLeftName("查找");
			tlv.setWinHeight(250);
			tlv.addRightTLV(new CloseWinTLV());

			CreateEditBoxTLV edit = new CreateEditBoxTLV();
			edit.setTitle("请输入要查找的玩家的全名或部分名字。"
					+ "如要查找名为<小强1号>的玩家，可以输入<小强1号>或<小强>");
			edit.setLeftName("查找");
			edit.setRightName("取消");
			edit.setContentLenMax(7);
			edit.setBoxType(CreateEditBoxTLV.TYPE_MSGBOX);
			edit.setInputType(CreateEditBoxTLV.INPUT_ANY << 4);
			edit.addLeftTLV(new ClearDataTLV());
			edit.addLeftTLV(new AddDataTLV((int) me.getRoleId()));
			edit.addLeftTLV(new AddEditBoxTLV());
			edit.addLeftTLV(new SendDataTLV(
					MmochatConstant.getClientModuleId(), MmochatMain
							.getModuleInstID(),
					MmochatConstant.MSGCODE_MMOCHAT_C_6_24, (int) 1));
			ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
			edit.addLeftTLV(wait);
			tlv.addItemEvent("根据名字查找", edit);

			edit = new CreateEditBoxTLV();
			edit.setTitle("请输入要查找的玩家的ID，玩家ID在查看对方资料时可以查询到，其中ID中字母不区分大小写。");
			edit.setLeftName("查找");
			edit.setRightName("取消");
			edit.setContentLenMax(10);
			edit.setBoxType(CreateEditBoxTLV.TYPE_MSGBOX);
			edit.setInputType(CreateEditBoxTLV.INPUT_ANY << 4);
			edit.addLeftTLV(new ClearDataTLV());
			edit.addLeftTLV(new AddDataTLV((int) me.getRoleId()));
			edit.addLeftTLV(new AddEditBoxTLV());
			edit.addLeftTLV(new SendDataTLV(
					MmochatConstant.getClientModuleId(), MmochatMain
							.getModuleInstID(),
					MmochatConstant.MSGCODE_MMOCHAT_C_6_24, (int) 2));
			wait = new ShowWaitingMsgBoxTLV();
			edit.addLeftTLV(wait);
			tlv.addItemEvent("根据ID查找", edit);

			return MmochatUtil.tlvResponse(req.getHallState(), tlv);
		}
		default:
			break;
		}
		// TODO:返回时要关闭快捷操作窗口
		return MmochatUtil.msgbox(req.getHallState(), type.toString()
				+ "功能尚未开通");
	}

	// 6.5 加点
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_5(SkymobiHandler handler,
			Mmochat_6_5C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			// 在其它服，不处理
			return MmochatUtil.msgbox(req.getHallState(), "当前位于跨服区，无法进行此操作!");
		}
		synchronized (me) {
			int num = Math.min(me.getSpace_point(), req.getNum());
			if (num <= 0) {
				return MmochatUtil.msgbox(req.getHallState(), "没有可分配的属性点!");
			}
			switch (req.getPoint_type()) {
			case 0:
				me.setASpacePointToAttack(num);
				break;
			case 1:
				me.setASpacePointToSprit(num);
				break;
			case 2:
				me.setASpacePointToBlood(num);
				break;
			case 3:
				me.setASpacePointToSpeed(num);
				break;
			default:
				break;
			}
		}
		try {
			MmochatDao.updateRolePoint(me);
		} catch (Exception e) {
			e.printStackTrace();
		}
		Mmochat_6_2S pack = new Mmochat_6_2S();
		pack.setPlayer(me);
		return pack;
	}

	// 6.9 玩家显示设置
	@SkymobiService
	public void handleC_6_9(SkymobiHandler handler, Mmochat_6_9C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return;
		}

		MmochatShowRoleSet set = MmochatShowRoleSet.get(req.getRoleSetValue());
		if (set == null) {
			return;
		}
		me.setShowRoleSet(set);
		log.debug(me.getName() + "将显示设置为<" + set.toString() + ">");
		try {
			MmochatDao.updateRoleShowSet(me);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// 聊天显示设置
	public static CreateTlvWin getShowChatSetTlv(MmochatPlayer me) {
		CreateTlvWin tlv = new CreateTlvWin();
		tlv.setWinType(WinType.List);
		tlv.setLeftName("更改");
		tlv.setRightName("返回");
		tlv.setTitle(MmochatQickStartType.聊天频道设置.toString());
		tlv.setWinHeight(250);
		tlv.setWinId(MmochatConstant.TLV_WIN_SET_SHOWCHAT);
		tlv.addRightTLV(new CloseWinTLV(MmochatConstant.TLV_WIN_SET_SHOWCHAT));
		for (MmochatChatChannelType channel : MmochatChatChannelType.values()) {
			String name = channel.toString();
			if (me.getShowChatSet().get(channel) != null
					&& me.getShowChatSet().get(channel)) {
				name += "(开启)";
			} else {
				name += "(关闭)";
			}
			tlv.addItemEvent(name, new ClearDataTLV(), new AddDataTLV(
					(int) channel.getValue()));
		}
		tlv.addLeftTLV(new SendDataTLV(MmochatConstant.getClientModuleId(),
				MmochatMain.getModuleInstID(),
				MmochatConstant.MSGCODE_MMOCHAT_C_6_10, (int) me.getRoleId()));
		ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
		wait.setShowCancel(false);
		tlv.addLeftTLV(wait);
		return tlv;
	}

	// 6.10 聊天显示设置
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_10(SkymobiHandler handler,
			Mmochat_6_10C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		MmochatChatChannelType channel = MmochatChatChannelType.get(req
				.getChatSetValue());
		if (channel == null) {
			return MmochatUtil.msgbox(req.getHallState(), "没有此聊天频道!");
		}
		String msg = "设置成功!" + channel.toString() + "频道已";
		if (me.getShowChatSet() == null) {
			me
					.setShowChatSet(new ConcurrentHashMap<MmochatChatChannelType, Boolean>());
			for (MmochatChatChannelType type : MmochatChatChannelType.values()) {
				me.getShowChatSet().put(type, true);
			}
		}
		Boolean ret = me.getShowChatSet().get(channel);
		if (ret == null || ret) {
			// 只有VIP才允许关闭喇叭
			// if (!me.isVip() && channel == MmochatChatChannelType.喇叭) {
			// return MmochatUtil.msgbox(req.getHallState(),
			// "只有会员才有权限关闭喇叭频道!按9键打开商城即可购买VIP。");
			// }
			me.getShowChatSet().put(channel, false);
			msg += "关闭";
			MmochatChatService.sendSystemMsgToPerson(me, channel.toString()
					+ "频道已关闭,按左软键进入聊天设置,可重新开启!");
		} else {
			me.getShowChatSet().put(channel, true);
			msg += "开启";
		}

		CreateTlvWin tlv = getShowChatSetTlv(me);

		CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
		msgbox.setContent(new Text(msg));
		msgbox.setLeftName("确定");

		try {
			MmochatDao.updateRoleChatSet(me);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return MmochatUtil.tlvResponse(req.getHallState(), new CloseWinTLV(
				MmochatConstant.TLV_WIN_SET_SHOWCHAT), tlv, msgbox);
	}

	// 比武切磋设置
	public static CreateTlvWin getPkSetTlv(MmochatPlayer me) {
		CreateTlvWin tlv = new CreateTlvWin();
		tlv.setWinType(WinType.List);
		tlv.setLeftName("更改");
		tlv.setRightName("返回");
		tlv.setTitle(MmochatQickStartType.切磋比武设置.toString());
		tlv.setWinHeight(250);
		tlv.setWinId(MmochatConstant.TLV_WIN_SET_PK);
		tlv.addRightTLV(new CloseWinTLV(MmochatConstant.TLV_WIN_SET_PK));

		String name = "切磋";
		if (me.isAcceptFriendlyPk()) {
			name += "(开启)";
		} else {
			name += "(关闭)";
		}
		tlv.addItemEvent(name, new ClearDataTLV(), new AddDataTLV((int) 0));

		name = "比武";
		if (me.isAcceptZhanjiPk()) {
			name += "(开启)";
		} else {
			name += "(关闭)";
		}
		tlv.addItemEvent(name, new ClearDataTLV(), new AddDataTLV((int) 1));

		tlv.addLeftTLV(new SendDataTLV(MmochatConstant.getClientModuleId(),
				MmochatMain.getModuleInstID(),
				MmochatConstant.MSGCODE_MMOCHAT_C_6_11, (int) me.getRoleId()));
		ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
		wait.setShowCancel(false);
		tlv.addLeftTLV(wait);
		return tlv;
	}

	// 6.11 比武切磋设置
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_11(SkymobiHandler handler,
			Mmochat_6_11C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (req.getIndex() != 0 && req.getIndex() != 1) {
			return MmochatUtil.msgbox(req.getHallState(), "没有此项设置!");
		}

		String msg = "设置成功!";
		if (req.getIndex() == 0) {
			if (me.isAcceptFriendlyPk()) {
				me.setAcceptFriendlyPk(false);
				msg += "当前状态为：拒绝切磋";
			} else {
				me.setAcceptFriendlyPk(true);
				msg += "当前状态为：允许切磋";
			}
			try {
				MmochatDao.updateRoleFriendlyPk(me);
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (req.getIndex() == 1) {
			if (me.isAcceptZhanjiPk()) {
				me.setAcceptZhanjiPk(false);
				msg += "当前状态为：拒绝比武";
			} else {
				me.setAcceptZhanjiPk(true);
				msg += "当前状态为：允许比武";
			}
			try {
				MmochatDao.updateRoleZhanjiPk(me);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		CreateTlvWin tlv = getPkSetTlv(me);

		CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
		msgbox.setContent(new Text(msg));
		msgbox.setLeftName("确定");

		return MmochatUtil.tlvResponse(req.getHallState(), new CloseWinTLV(
				MmochatConstant.TLV_WIN_SET_PK), tlv, msgbox);
	}

	// 其它系统设置
	public static CreateTlvWin getOtherSystemSetTlv(MmochatPlayer me) {
		CreateTlvWin tlv = new CreateTlvWin();
		tlv.setWinType(WinType.List);
		tlv.setLeftName("更改");
		tlv.setRightName("返回");
		tlv.setTitle(MmochatQickStartType.其它系统设置.toString());
		tlv.setWinHeight(250);
		tlv.setWinId(MmochatConstant.TLV_WIN_SET_OTHER);
		tlv.addRightTLV(new CloseWinTLV(MmochatConstant.TLV_WIN_SET_OTHER));

		for (MmochatOtherSystemSettingType type : MmochatOtherSystemSettingType
				.values()) {
			if (!type.isShow()) {
				continue;
			}
			String name = type.toString();
			boolean set = me.getOtherSystemSettingByType(type);
			if (set) {
				name += MmochatUtil.wrapColor("\n已开启", Color.yellow);
			} else {
				name += MmochatUtil.wrapColor("\n已关闭", Color.yellow);
			}
			tlv.addItemEvent(name, new ClearDataTLV(), new AddDataTLV(
					(int) type.getValue()));
		}

		tlv.addLeftTLV(new SendDataTLV(MmochatConstant.getClientModuleId(),
				MmochatMain.getModuleInstID(),
				MmochatConstant.MSGCODE_MMOCHAT_C_6_20, (int) me.getRoleId()));
		ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
		wait.setShowCancel(false);
		tlv.addLeftTLV(wait);
		return tlv;
	}

	// 6.20 其它系统设置
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_20(SkymobiHandler handler,
			Mmochat_6_20C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		MmochatOtherSystemSettingType type = MmochatOtherSystemSettingType
				.get(req.getSetType());
		if (type == null) {
			return MmochatUtil.msgbox(req.getHallState(), "没有此项设置!");
		}

		String msg = "设置成功!";
		switch (type) {
		case 远程交易:
			if (me.getOtherSystemSettingByType(type)) {
				me.getOtherSystemSetting().put(type, false);
				msg += "当前状态为：拒绝远程交易";
			} else {
				me.getOtherSystemSetting().put(type, true);
				msg += "当前状态为：允许远程交易";
			}
			break;
		case 近程交易:
			if (me.getOtherSystemSettingByType(type)) {
				me.getOtherSystemSetting().put(type, false);
				msg += "当前状态为：拒绝近距离交易";
			} else {
				me.getOtherSystemSetting().put(type, true);
				msg += "当前状态为：允许近距离交易";
			}
			break;
		case 他人查看装备:
			if (me.getOtherSystemSettingByType(type)) {
				me.getOtherSystemSetting().put(type, false);
				msg += "当前状态为：拒绝他人查看我的装备信息";
			} else {
				me.getOtherSystemSetting().put(type, true);
				msg += "当前状态为：允许他人查看我的装备信息";
			}
			break;
		case 显示战斗背景: {
			if (me.getOtherSystemSettingByType(type)) {
				me.getOtherSystemSetting().put(type, false);
				msg += "当前状态为：关闭战斗背景。战斗更流畅。";
			} else {
				me.getOtherSystemSetting().put(type, true);
				msg += "当前状态为：显示战斗背景。如果战斗不够流畅，可以选择关闭战斗背景。";
			}
			// 下发更新玩家状态
			Mmochat_1_16S effect = new Mmochat_1_16S();
			effect.setMe(me);
			MmochatUtil.sendCommonPack(me, effect);
			break;
		}
		case 显示雨雪天气: {
			if (me.getOtherSystemSettingByType(type)) {
				me.getOtherSystemSetting().put(type, false);
				msg += "当前状态为：关闭雨雪天气。";
			} else {
				me.getOtherSystemSetting().put(type, true);
				msg += "当前状态为：显示雨雪天气。";
			}
			// 下发更新玩家状态
			Mmochat_1_16S effect = new Mmochat_1_16S();
			effect.setMe(me);
			MmochatUtil.sendCommonPack(me, effect);
			break;
		}
		case 战斗过程时间: {
			// true:正常时间
			// false:缩短时间
			if (me.getOtherSystemSettingByType(type)) {
				me.getOtherSystemSetting().put(type, false);
				msg += "当前状态为：在战斗中，动画播放时间缩短。"
						+ MmochatUtil.wrapColor("受手机性能影响，"
								+ "有些手机在此状态下有可能导致战斗动画播放到一半时，" + "被强制跳过动画!",
								Color.yellow);
			} else {
				me.getOtherSystemSetting().put(type, true);
				msg += "当前状态为：在战斗中，动画播放时间较长，大部分手机在此状态下战斗动画能够播放完整。";
			}
			break;
		}
		case 不显示他人等级: {
			if (me.getOtherSystemSettingByType(type)) {
				me.getOtherSystemSetting().put(type, false);
				msg += "当前状态为：显示他人等级。需要在切换地图或换线后，才会生效。";
			} else {
				me.getOtherSystemSetting().put(type, true);
				msg += "当前状态为：不显示他人等级。需要在切换地图或换线后，才会生效。";
			}
			break;
		}
		default:
			break;
		}
		try {
			MmochatDao.updateRoleOtherSetting(me);
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		CreateTlvWin tlv = getOtherSystemSetTlv(me);

		CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
		msgbox.setContent(new Text(msg));
		msgbox.setLeftName("确定");

		return MmochatUtil.tlvResponse(req.getHallState(), new CloseWinTLV(
				MmochatConstant.TLV_WIN_SET_OTHER), tlv, msgbox);
	}

	// 新手免费洗点
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_4(SkymobiHandler handler,
			Mmochat_6_4C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}

		boolean isFreeDay = false;
		if (MmochatTempActivityService.freePointDay != null
				&& MmochatTempActivityService.freePointDay.length > 0) {
			// 全民免费洗点
			long curTick = System.currentTimeMillis();
			for (int i = 0; i < MmochatTempActivityService.freePointDay.length; i++) {
				String startDate = MmochatTempActivityService.freePointDay[i];
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				Date start = null;
				try {
					start = sdf.parse(startDate);
				} catch (ParseException e) {
					continue;
				}
				if (curTick >= start.getTime()
						&& curTick < start.getTime()
								+ MmochatConstant.MS_PER_DAY) {
					isFreeDay = true;
					break;
				}
			}
		}

		if (!isFreeDay) {
			if (me.getLevel() > MmochatConstant.getMaxLevelToFreeSetPoint()) {
				return MmochatUtil.msgbox(req.getHallState(), "只有"
						+ MmochatConstant.getMaxLevelToFreeSetPoint()
						+ "级以前的新手才能到我这免费洗点。您的修为过高,我已无能为力!");
			}
		}

		int delBloodPoint = me.getBlood_point() - me.getLevel();
		int delSpritPoint = me.getSprit_point() - me.getLevel();
		int delAttackPoint = me.getAttack_point() - me.getLevel();
		int delSpeedPoint = me.getSpeed_point() - me.getLevel();
		int delAttackGiftPoint = me.getAttack_gift_point();
		int delSpritGiftPoint = me.getSprit_gift_point();
		int delBloodGiftPoint = me.getBlood_gift_point();
		int delDefendGiftPoint = me.getDefend_gift_point();
		int delSpeedGiftPoint = me.getSpeed_gift_point();

		if (delBloodPoint == 0 && delSpritPoint == 0 && delAttackPoint == 0
				&& delSpeedPoint == 0 && delAttackGiftPoint == 0
				&& delSpritGiftPoint == 0 && delBloodGiftPoint == 0
				&& delDefendGiftPoint == 0 && delSpeedGiftPoint == 0) {
			return MmochatUtil.msgbox(req.getHallState(), "您没有可洗的属性点和天赋点!");
		}
		me.delBlood_point(delBloodPoint);
		me.delSprit_point(delSpritPoint);
		me.delAttack_point(delAttackPoint);
		me.delSpeed_point(delSpeedPoint);
		me.addSpace_point(delBloodPoint + delSpritPoint + delAttackPoint
				+ delSpeedPoint);
		me.setAttack_gift_point(0);
		me.setSprit_gift_point(0);
		me.setBlood_gift_point(0);
		me.setDefend_gift_point(0);
		me.setSpeed_gift_point(0);
		me.addSpace_gift_point(delAttackGiftPoint + delSpritGiftPoint
				+ delBloodGiftPoint + delDefendGiftPoint + delSpeedGiftPoint);
		try {
			MmochatDao.updateRolePoint(me);
		} catch (Exception e) {
			e.printStackTrace();
			me.delBlood_point(-1 * delBloodPoint);
			me.delSprit_point(-1 * delSpritPoint);
			me.delAttack_point(-1 * delAttackPoint);
			me.delSpeed_point(-1 * delSpeedPoint);
			me
					.addSpace_point(-1
							* (delBloodPoint + delSpritPoint + delAttackPoint + delSpeedPoint));
			me.setAttack_gift_point(delAttackGiftPoint);
			me.setSprit_gift_point(delSpritGiftPoint);
			me.setBlood_gift_point(delBloodGiftPoint);
			me.setDefend_gift_point(delDefendGiftPoint);
			me.setSpeed_gift_point(delSpeedGiftPoint);
			me
					.addSpace_gift_point(-1
							* (delAttackGiftPoint + delSpritGiftPoint
									+ delBloodGiftPoint + delDefendGiftPoint + delSpeedGiftPoint));
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		return MmochatUtil.msgbox(req.getHallState(),
				"您的属性点和天赋点已全部洗去,您现在可以进入人物面板重新分配您的属性点和天赋点了!");
	}

	// 6.12 快捷操作
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_12(SkymobiHandler handler,
			Mmochat_6_12C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			return MmochatUtil.msgbox(req.getHallState(), "跨服区内无法进行此操作!");
		}
		if (req.getVersion() != MmochatConstant.multiPlayerTeamVersion) {
			return MmochatUtil.msgbox(req.getHallState(), "您的版本过旧,请退出重新进入游戏!");
		}

		MmochatMultiPlayerTeamType type = MmochatMultiPlayerTeamType.get(req
				.getQuickStartValue());
		if (type == null) {
			return MmochatUtil.msgbox(req.getHallState(), "此功能暂未开放!");
		}
		switch (type) {
		case 帮派:
			if (!me.hasGang()) {
				return MmochatUtil.msgbox(req.getHallState(), "您尚未加入帮派!");
			}
			// 打开帮派界面
			MmochatGang myGang = MmochatGangService.getGangById(me.getGangId());
			if (myGang == null) {
				return MmochatUtil.msgbox(req.getHallState(), "您尚未加入帮派!");
			}
			MmochatGangMember myInfo = myGang.getMembers().get(me.getRoleId());
			if (myInfo == null) {
				return MmochatUtil.msgbox(req.getHallState(), "您尚未加入帮派!");
			}
			Mmochat_15_2S pack = new Mmochat_15_2S();
			pack.setHallState(req.getHallState());
			pack.setGang(myGang);
			pack.setMyType(myInfo.getType());
			return pack;
		case 战队:
			return MmochatUtil.msgbox(req.getHallState(), "跨服战队暂未开启，敬请期待!");
			// if (!me.hasPkTeam()) {
			// return MmochatUtil.msgbox(req.getHallState(), "您还没有自己的战队!");
			// }
			// TODO:打开战队界面
		default:
			break;
		}
		return MmochatUtil.msgbox(req.getHallState(), "此功能暂未开放!");
	}

	// 6.13 查看其它玩家信息
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_13(SkymobiHandler handler,
			Mmochat_6_13C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		MmochatPlayer he = MmochatMainService.players
				.get(req.getTargetRoleId());
		if (he == null) {
			return MmochatUtil.msgbox(req.getHallState(), "该玩家当前不在线或已掉线!");
		}
		CreateTlvWin tlv = getUserInfoTlv(me, he);
		return MmochatUtil.tlvResponse(req.getHallState(), tlv);
	}

	// 处理比武请求
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_14(SkymobiHandler handler,
			Mmochat_6_14C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		MmochatPlayer he = MmochatMainService.players.get(req
				.getRequestRoleId());
		if (he == null) {
			return MmochatUtil.msgbox(req.getHallState(), "对方已下线!");
		}
		if (req.getDeal() == 1) {
			// 拒绝
			if (me.getMapId() != MmochatConstant.mapId_比武场
					&& me.getMapId() != MmochatConstant.mapId_跨服擂台) {
				return null;
			}
			MmochatChatService.sendSystemMsgToPerson(he, me.getName()
					+ "拒绝了你的比武请求。");
		} else if (req.getDeal() == 0) {
			// 查看比武对方信息
			if (!MmochatMapService.isInZhangJiPkRange(me)) {
				return MmochatUtil.msgbox(req.getHallState(), "您不在比武场内!");
			}
			if (!MmochatMapService.isInZhangJiPkRange(he)) {
				return MmochatUtil.msgbox(req.getHallState(), "对方不在比武场内!");
			}
			if (!me.isInSameMapLine(he)) {
				return MmochatUtil.msgbox(req.getHallState(), "对方已经离开!");
			}
			if (he.isInTeam()) {
				if (MmochatTeamService.getTeamState(he) != MmochatTeamStateType.队长) {
					return MmochatUtil
							.msgbox(req.getHallState(), "对方已经加入其它队伍!");
				}
			}
			if (he.isInBattle() || !he.isFreeState()) {
				return MmochatUtil.msgbox(req.getHallState(), "对方现在无法比武!");
			}
			if (me.isInBattle() || !me.isFreeState()) {
				return null;
			}
			List<MmochatPlayer> targetList = new ArrayList<MmochatPlayer>();
			if (he.isInTeam()) {
				MmochatTeam team = MmochatTeamService.teams.get(he.getTeamId());
				if (team == null) {
					he.leaveTeam();
					targetList.add(he);
				} else {
					for (Integer roleId : team.getMemberId().values()) {
						MmochatPlayer member = MmochatMainService.players
								.get(roleId);
						if (member != null) {
							targetList.add(member);
						}
					}
				}
			} else {
				targetList.add(he);
			}

			List<MmochatPlayer> requestList = new ArrayList<MmochatPlayer>();
			if (me.isInTeam()) {
				MmochatTeam team = MmochatTeamService.teams.get(me.getTeamId());
				if (team == null) {
					me.leaveTeam();
					requestList.add(me);
				} else {
					for (Integer roleId : team.getMemberId().values()) {
						MmochatPlayer member = MmochatMainService.players
								.get(roleId);
						if (member != null) {
							requestList.add(member);
						}
					}
				}
			} else {
				requestList.add(me);
			}

			if (requestList.contains(he) || targetList.contains(me)) {
				return MmochatUtil.closeWindowAndShowMsgbox(req.getHallState(),
						"不能与队友比武!", MmochatConstant.TLV_WIN_CLICKROLE);
			}
			if (!he.lockState(MmochatRoleStateType.接受比武时)) {
				return MmochatUtil.msgbox(req.getHallState(), "对方现在无法比武!");
			} else {
				if (!me.lockState(MmochatRoleStateType.接受比武时)) {
					he.unLockState();
				} else {
					// 双方状态已锁定，下发双方信息
					MmochatPkRequest pkRequest = new MmochatPkRequest();
					pkRequestMap.put(pkRequest.getId(), pkRequest);
					pkRequest.getAgreeMap().put(me.getRoleId(), false);
					pkRequest.getAgreeMap().put(he.getRoleId(), false);

					String msg = "";
					for (MmochatPlayer role : targetList) {
						msg += MmochatUtil.wrapColor(role.getName(),
								Color.green);
						msg += "," + role.getLevel() + "级,"
								+ role.getFamily().getName() + "\n";
					}
					msg += "\n是否接受比武?";
					CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
					msgbox.setContent(new Text(msg));
					msgbox.setLeftName("接受");
					msgbox.addLeftTLV(new ClearDataTLV());
					msgbox.addLeftTLV(new AddDataTLV((int) me.getRoleId()));
					msgbox.addLeftTLV(new AddDataTLV((int) pkRequest.getId()));
					msgbox.addLeftTLV(new SendDataTLV(MmochatConstant
							.getClientModuleId(),
							MmochatMain.getModuleInstID(),
							MmochatConstant.MSGCODE_MMOCHAT_C_6_15, (int) 0));

					CreateMsgBoxTLV wait = new CreateMsgBoxTLV();
					wait.setContent(new Text("请等待对方的意见，点<取消>则比武取消。"));
					wait.setRightName("取消");
					wait.addRightTLV(new ClearDataTLV());
					wait.addRightTLV(new AddDataTLV((int) me.getRoleId()));
					wait.addRightTLV(new AddDataTLV((int) pkRequest.getId()));
					wait.addRightTLV(new SendDataTLV(MmochatConstant
							.getClientModuleId(),
							MmochatMain.getModuleInstID(),
							MmochatConstant.MSGCODE_MMOCHAT_C_6_15, (int) 1));
					msgbox.addLeftTLV(wait);

					msgbox.setRightName("拒绝");
					msgbox.addRightTLV(new ClearDataTLV());
					msgbox.addRightTLV(new AddDataTLV((int) me.getRoleId()));
					msgbox.addRightTLV(new AddDataTLV((int) pkRequest.getId()));
					msgbox.addRightTLV(new SendDataTLV(MmochatConstant
							.getClientModuleId(),
							MmochatMain.getModuleInstID(),
							MmochatConstant.MSGCODE_MMOCHAT_C_6_15, (int) 1));

					CtrlTLVStructureRequest pack = MmochatUtil
							.tlvResponseWithoutHallState(msgbox);
					MmochatUtil.sendCommonPack(me, pack);

					msg = "";
					for (MmochatPlayer role : requestList) {
						msg += MmochatUtil.wrapColor(role.getName(),
								Color.green);
						msg += "," + role.getLevel() + "级,"
								+ role.getFamily().getName() + "\n";
					}
					msg += "\n是否接受比武?";
					msgbox = new CreateMsgBoxTLV();
					msgbox.setContent(new Text(msg));
					msgbox.setLeftName("接受");
					msgbox.addLeftTLV(new ClearDataTLV());
					msgbox.addLeftTLV(new AddDataTLV((int) he.getRoleId()));
					msgbox.addLeftTLV(new AddDataTLV((int) pkRequest.getId()));
					msgbox.addLeftTLV(new SendDataTLV(MmochatConstant
							.getClientModuleId(),
							MmochatMain.getModuleInstID(),
							MmochatConstant.MSGCODE_MMOCHAT_C_6_15, (int) 0));

					wait = new CreateMsgBoxTLV();
					wait.setContent(new Text("请等待对方的意见，点<取消>则比武取消。"));
					wait.setRightName("取消");
					wait.addRightTLV(new ClearDataTLV());
					wait.addRightTLV(new AddDataTLV((int) he.getRoleId()));
					wait.addRightTLV(new AddDataTLV((int) pkRequest.getId()));
					wait.addRightTLV(new SendDataTLV(MmochatConstant
							.getClientModuleId(),
							MmochatMain.getModuleInstID(),
							MmochatConstant.MSGCODE_MMOCHAT_C_6_15, (int) 1));
					msgbox.addLeftTLV(wait);

					msgbox.setRightName("拒绝");
					msgbox.addRightTLV(new ClearDataTLV());
					msgbox.addRightTLV(new AddDataTLV((int) he.getRoleId()));
					msgbox.addRightTLV(new AddDataTLV((int) pkRequest.getId()));
					msgbox.addRightTLV(new SendDataTLV(MmochatConstant
							.getClientModuleId(),
							MmochatMain.getModuleInstID(),
							MmochatConstant.MSGCODE_MMOCHAT_C_6_15, (int) 1));

					pack = MmochatUtil.tlvResponseWithoutHallState(msgbox);
					MmochatUtil.sendCommonPack(he, pack);
				}
			}
		}
		return null;
	}

	// 双方上传比武意见
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_15(SkymobiHandler handler,
			Mmochat_6_15C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		MmochatPkRequest pkRequest = pkRequestMap.get(req.getRequestId());
		if (pkRequest == null) {
			me.unLockState();
			return null;
		}
		if (req.getDeal() == 0) {
			// 同意
			if (pkRequest.isAllAgree()) {
				return null;
			}
			synchronized (pkRequest) {
				pkRequest.getAgreeMap().put(me.getRoleId(), true);
			}
			if (pkRequest.isAllAgree()) {
				// 双方都已同意，开始比武
				MmochatPlayer he = null;
				for (Integer roleId : pkRequest.getAgreeMap().keySet()) {
					if (roleId != me.getRoleId()) {
						he = MmochatMainService.players.get(roleId);
						if (he == null) {
							me.unLockState();
							he = MmochatMainService.getRoleFromBuffer(roleId);
							if (he != null) {
								he.unLockState();
							}
							return MmochatUtil.msgbox(req.getHallState(),
									"对方已经下线!");
						}
						break;
					}
				}

				if (he.isInTeam()) {
					if (MmochatTeamService.getTeamState(he) != MmochatTeamStateType.队长) {
						me.unLockState();
						he.unLockState();
						return MmochatUtil.msgbox(req.getHallState(),
								"对方已经加入其它队伍!");
					}
				}
				if (he.isInBattle()) {
					me.unLockState();
					he.unLockState();
					return MmochatUtil.msgbox(req.getHallState(), "对方现在无法比武!");
				}
				if (me.isInBattle()) {
					me.unLockState();
					he.unLockState();
					return null;
				}
				List<MmochatPlayer> targetList = new ArrayList<MmochatPlayer>();
				if (he.isInTeam()) {
					MmochatTeam team = MmochatTeamService.teams.get(he
							.getTeamId());
					if (team == null) {
						he.leaveTeam();
						targetList.add(he);
					} else {
						for (Integer roleId : team.getMemberId().values()) {
							MmochatPlayer member = MmochatMainService
									.getRoleFromBuffer(roleId);
							if (member != null) {
								targetList.add(member);
							}
						}
					}
				} else {
					targetList.add(he);
				}

				List<MmochatPlayer> requestList = new ArrayList<MmochatPlayer>();
				if (me.isInTeam()) {
					MmochatTeam team = MmochatTeamService.teams.get(me
							.getTeamId());
					if (team == null) {
						me.leaveTeam();
						requestList.add(me);
					} else {
						for (Integer roleId : team.getMemberId().values()) {
							MmochatPlayer member = MmochatMainService
									.getRoleFromBuffer(roleId);
							if (member != null) {
								requestList.add(member);
							}
						}
					}
				} else {
					requestList.add(me);
				}

				if (requestList.contains(he) || targetList.contains(me)) {
					me.unLockState();
					he.unLockState();
					return MmochatUtil.closeWindowAndShowMsgbox(req
							.getHallState(), "不能与队友比武!",
							MmochatConstant.TLV_WIN_CLICKROLE);
				}

				if (me.getMapId() == MmochatConstant.mapId_比武场) {
					for (MmochatPlayer role : requestList) {
						if (role.getZhanji() < MmochatConstant.minZhangJiNeedInPkMap) {
							me.unLockState();
							he.unLockState();
							return MmochatUtil.closeWindowAndShowMsgbox(req
									.getHallState(), role.getName() + "的战绩不足!",
									MmochatConstant.TLV_WIN_CLICKROLE);
						}
					}
					for (MmochatPlayer role : targetList) {
						if (role.getZhanji() < MmochatConstant.minZhangJiNeedInPkMap) {
							me.unLockState();
							he.unLockState();
							return MmochatUtil.closeWindowAndShowMsgbox(req
									.getHallState(), role.getName() + "的战绩不足!",
									MmochatConstant.TLV_WIN_CLICKROLE);
						}
					}

					me.unLockState();
					he.unLockState();
					// 进入战斗
					MmochatBattleService.enterPVPBattle(me.getMapId(),
							(byte) me.getLine(), requestList, targetList,
							MmochatBattleType.比武场比武);
				} else if (me.getMapId() == MmochatConstant.mapId_跨服擂台) {
					for (MmochatPlayer role : requestList) {
						if (role.getPk_score() < MmochatConstant.minPkScoreNeed) {
							me.unLockState();
							he.unLockState();
							return MmochatUtil.closeWindowAndShowMsgbox(req
									.getHallState(),
									role.getName() + "的竞技点不足!",
									MmochatConstant.TLV_WIN_CLICKROLE);
						}
					}
					for (MmochatPlayer role : targetList) {
						if (role.getPk_score() < MmochatConstant.minPkScoreNeed) {
							me.unLockState();
							he.unLockState();
							return MmochatUtil.closeWindowAndShowMsgbox(req
									.getHallState(),
									role.getName() + "的竞技点不足!",
									MmochatConstant.TLV_WIN_CLICKROLE);
						}
					}

					me.unLockState();
					he.unLockState();
					// 进入战斗
					MmochatBattleService.enterPVPBattle(me.getMapId(),
							(byte) me.getLine(), requestList, targetList,
							MmochatBattleType.跨服擂台比武);

				}
				pkRequestMap.remove(pkRequest.getId());
			}
		} else if (req.getDeal() == 1) {
			// 拒绝
			if (pkRequest.isAllAgree()) {
				// 已经全部同意
				return null;
			}
			synchronized (pkRequest) {
				if (pkRequest.isAllAgree()) {
					// 已经全部同意
					return null;
				}
				pkRequest.getAgreeMap().put(me.getRoleId(), false);
			}
			for (Integer roleId : pkRequest.getAgreeMap().keySet()) {
				MmochatPlayer role = MmochatMainService
						.getRoleFromBuffer(roleId);
				if (role != null) {
					role.unLockState();
					if (role.getRoleId() != me.getRoleId()) {
						MmochatUtil.sendCommonMsgbox(role, "对方已取消比武");
					}
				}
			}
			pkRequestMap.remove(pkRequest.getId());
		}
		return null;
	}

	// 设置同屏显示上限
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_16(SkymobiHandler handler,
			Mmochat_6_16C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		int num = 0;
		try {
			num = Integer.parseInt(req.getInfo());
		} catch (NumberFormatException e) {
			return MmochatUtil.msgbox(req.getHallState(), "请输入数字!");
		}
		if (num <= 0) {
			return MmochatUtil.msgbox(req.getHallState(), "只能设置大于0的数字!");
		}

		if (num > 60) {
			return MmochatUtil.msgbox(req.getHallState(),
					"最大只能设置60!设置过大容易使游戏不流畅。");
		}
		if (num != me.getMax_screen_role_num()) {
			int oldNum = me.getMax_screen_role_num();
			me.setMax_screen_role_num(num);
			try {
				MmochatDao.updateScreenRoleNum(me);
			} catch (Exception e) {
				me.setMax_screen_role_num(oldNum);
				e.printStackTrace();
				return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
			}
		}

		CreateTlvWin tlv = new CreateTlvWin();
		tlv.setWinType(WinType.Text);
		tlv.setTitle("同屏人数限制");
		tlv.setRightName("返回");
		tlv.setLeftName("设置");
		tlv.setWinHeight(250);
		tlv.setWinId(MmochatConstant.TLV_WIN_SET_SCREEN_ROLE_NUM);
		tlv.addRightTLV(new CloseWinTLV(
				MmochatConstant.TLV_WIN_SET_SCREEN_ROLE_NUM));

		String msg = MmochatUtil.wrapColor("当前同屏人数上限:"
				+ me.getMax_screen_role_num() + "人", Color.yellow);
		msg += "\n\n";
		msg += MmochatUtil.wrapColor("  同屏人数是指一个屏幕内最多看到的其它玩家人数。同屏人数设置越高，"
				+ "游戏越不流畅，但您能看到的玩家就越多，而且增加同屏人数，并不会增加流量负担。"
				+ "所以建议保证流畅的前提下，尽可能高得设置同屏人数，以获得最好的游戏体验。"
				+ "\n\n  建议设置范围：10人~50人", Color.green);

		CreateEditBoxTLV edit = new CreateEditBoxTLV();
		edit.setTitle("请输入同屏人数上限");
		edit.setLeftName("确定");
		edit.setRightName("取消");
		edit.setContentLenMax(2);
		edit.setBoxType(CreateEditBoxTLV.TYPE_MSGBOX);
		edit.setInputType(CreateEditBoxTLV.INPUT_NUM << 4);
		edit.addLeftTLV(new AddDataTLV((int) me.getRoleId()));
		edit.addLeftTLV(new AddEditBoxTLV());
		edit.addLeftTLV(new SendDataTLV(MmochatConstant.getClientModuleId(),
				MmochatMain.getModuleInstID(),
				MmochatConstant.MSGCODE_MMOCHAT_C_6_16, null));
		ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
		wait.setShowCancel(false);
		edit.addLeftTLV(wait);
		tlv.addLeftTLV(edit);

		tlv.setContent(new Text(msg));
		return MmochatUtil.tlvResponse(req.getHallState(), new CloseWinTLV(
				MmochatConstant.TLV_WIN_SET_SCREEN_ROLE_NUM), tlv);
	}

	// 6.17 加天赋点
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_17(SkymobiHandler handler,
			Mmochat_6_17C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			// 在其它服，不处理
			return MmochatUtil.msgbox(req.getHallState(), "当前位于跨服区，无法进行此操作!");
		}
		int num = req.getPointNum();
		if (num <= 0) {
			return MmochatUtil.msgbox(req.getHallState(), "分配的点数必需大于0!");
		}
		if (me.getSpace_gift_point() <= 0) {
			return MmochatUtil.msgbox(req.getHallState(), "没有可分配的天赋点!");
		}
		num = Math.min(num, me.getSpace_gift_point());
		boolean success;
		synchronized (me) {
			success = false;
			switch (req.getPoint_type()) {
			case 0:
				success = me.setASpacePointToAttackGift(num);
				break;
			case 1:
				success = me.setASpacePointToSpritGift(num);
				break;
			case 2:
				success = me.setASpacePointToBloodGift(num);
				break;
			case 3:
				success = me.setASpacePointToDefendGift(num);
				break;
			case 4:
				success = me.setASpacePointToSpeedGift(num);
				break;
			default:
				break;
			}
		}
		if (!success) {
			return MmochatUtil.msgbox(req.getHallState(), "每项天赋点最多可分配"
					+ MmochatConstant.getMaxNumPerGift(me.getLife_turn())
					+ "点!");
		}
		try {
			MmochatDao.updateRoleGiftPoint(me);
		} catch (Exception e) {
			e.printStackTrace();
		}
		Mmochat_6_2S pack = new Mmochat_6_2S();
		pack.setPlayer(me);
		return pack;
	}

	// 6.18 查看其它玩家身上的装备
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_18(SkymobiHandler handler,
			Mmochat_6_18C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		MmochatPlayer he = MmochatMainService.players
				.get(req.getTargetRoleId());
		if (he == null) {
			return MmochatUtil.msgbox(req.getHallState(), "对方已下线!");
		}
		// 设置了拒绝查看
		if (!he
				.getOtherSystemSettingByType(MmochatOtherSystemSettingType.他人查看装备)) {
			return MmochatUtil.msgbox(req.getHallState(), "对方设置了拒绝被他人查看装备信息!");
		}

		CreateTlvWin tlv = new CreateTlvWin();
		tlv.setWinType(WinType.List);
		tlv.setLeftName("查看");
		tlv.setRightName("返回");
		tlv.setTitle(he.getName());
		tlv.setWinHeight(208);
		tlv.addRightTLV(new CloseWinTLV());

		for (MmochatEquipPlaceType place : MmochatEquipPlaceType.values()) {
			MmochatPackageGrid grid = he.getMyPackage().get(place.getValue());
			String item = MmochatUtil.wrapColor(place.getEquipType().toString()
					+ ":", Color.yellow);
			int objId = -1;
			MmochatCommonObject obj = grid.getObject();
			if (obj == null) {
				item += "-";
			} else {
				objId = obj.getId();
				if (obj.getEquipName() != null) {
					item += MmochatUtil.wrapColor(obj.getEquipName(), obj
							.getEquipQuality().getColor());
					if (obj.getEquipModifyLevel() > 0) {
						item += "\n改造:+" + obj.getEquipModifyLevel();
					} else {
						item += "\n改造:-";
					}
				} else {
					item += MmochatUtil.wrapColor(obj.getName(), Color.yellow);
				}
			}

			tlv.addItemEvent(item, new ClearDataTLV(), new AddDataTLV(
					(int) objId));
		}

		tlv.addLeftTLV(new SendDataTLV(MmochatConstant.getClientModuleId(),
				MmochatMain.getModuleInstID(),
				MmochatConstant.MSGCODE_MMOCHAT_C_5_7, (int) he.getRoleId()));
		tlv.addLeftTLV(new ShowWaitingMsgBoxTLV());

		return MmochatUtil.tlvResponse(req.getHallState(), tlv);
	}

	// 强制杀戮
	@SuppressWarnings("deprecation")
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_19(SkymobiHandler handler,
			Mmochat_6_19C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		MmochatPlayer he = MmochatMainService.players
				.get(req.getTargetRoleId());
		if (he == null) {
			return MmochatUtil.msgbox(req.getHallState(), "该玩家当前不在线!");
		}
		if (me.getLevel() < 30) {
			return MmochatUtil.msgbox(req.getHallState(), "30级以下不能击杀他人!");
		}
		if (he.getLevel() < 30) {
			return MmochatUtil.msgbox(req.getHallState(), "不能击杀30级以下的玩家!");
		}

		MmochatMap curMap = MmochatMapService.getMapByMapId(me.getMapId());

		// 在遇怪地图切磋则是进行强制PK
		if (curMap.isWalkToBattle()) {
			if (!curMap.isCanFriendlyPk()) {
				return MmochatUtil.msgbox(req.getHallState(), "本地图不允许杀戮!");
			}
			if (MmochatTeamService.getTeamState(me) == MmochatTeamStateType.队员) {
				return MmochatUtil.msgbox(req.getHallState(), "组队中只有队长才能发起战斗!");
			}
			if (me.isInBattle()) {
				return null;
			}
			if (me.isInDeal()) {
				return null;
			}
			if (!me.isInSameMapLine(he)) {
				return MmochatUtil
						.msgbox(req.getHallState(), "该玩家已经离开本地图或本线路!");
			}
			if (!me.isFreeState()) {
				return null;
			}

			// 如果是组队状态,需要将所有队员加入列表
			MmochatPlayer hisTeamLeader = null;
			List<MmochatPlayer> targetList = new ArrayList<MmochatPlayer>();
			if (he.isInTeam()) {
				MmochatTeam team = MmochatTeamService.teams.get(he.getTeamId());
				if (team == null) {
					hisTeamLeader = he;
					he.leaveTeam();
					targetList.add(he);
				} else {
					for (Integer roleId : team.getMemberId().values()) {
						MmochatPlayer member = MmochatMainService
								.getRoleFromBuffer(roleId);
						if (member != null) {
							targetList.add(member);
							if (team.isTeamLeader(roleId)) {
								hisTeamLeader = member;
							}
						}
					}
				}
			} else {
				hisTeamLeader = he;
				targetList.add(he);
			}
			if (hisTeamLeader == null) {
				return MmochatUtil.msgbox(req.getHallState(),
						"对方队伍的队长掉线,暂时无法发起战斗!");
			}
			if (!hisTeamLeader.isFreeState()) {
				return MmochatUtil.msgbox(req.getHallState(), "对方忙，暂时无法进行战斗!");
			}
			if (hisTeamLeader.isInBattle()) {
				return MmochatUtil
						.msgbox(req.getHallState(), "对方正在战斗中,无法进行击杀!");
			}
			if (hisTeamLeader.getMapId() != me.getMapId()
					|| hisTeamLeader.getLine() != me.getLine()) {
				return MmochatUtil.msgbox(req.getHallState(), "对方已经离开!");
			}

			// 如果是组队状态,需要将所有队员加入列表
			List<MmochatPlayer> requestList = new ArrayList<MmochatPlayer>();
			if (me.isInTeam()) {
				MmochatTeam team = MmochatTeamService.teams.get(me.getTeamId());
				if (team == null) {
					me.leaveTeam();
					requestList.add(me);
				} else {
					for (Integer roleId : team.getMemberId().values()) {
						MmochatPlayer member = MmochatMainService
								.getRoleFromBuffer(roleId);
						if (member != null) {
							requestList.add(member);
						}
					}
				}
			} else {
				requestList.add(me);
			}

			if (requestList.contains(he) || targetList.contains(me)) {
				return MmochatUtil.msgbox(req.getHallState(), "不能与队友战斗!");
			}

			if (requestList.size() == 1
					&& (me.getTrueLevel() + 30 < he.getTrueLevel())) {
				return MmochatUtil.msgbox(req.getHallState(),
						"对方等级超过您30级以上，不能击杀!");
			}

			int maxTimes = 0;
			Date now = new Date();
			for (MmochatPlayer member : requestList) {
				MmochatDailyActivity activity;
				Date lastDate; // 上次参加活动日期
				activity = member.getDailyActivities().get(
						MmochatDailyActivityType.杀人);
				int times = 0;
				if (activity == null) {
					// 第一次参加此活动
					times = 0;
					activity = new MmochatDailyActivity();
					activity.setType(MmochatDailyActivityType.杀人);
					activity.setLastTime(now.getTime());
					activity.setDailyTimes(1);
					member.addDailyActivity(activity);
				} else {
					lastDate = new Date(activity.getLastTime());
					if (now.getDate() == lastDate.getDate()
							&& now.getMonth() == lastDate.getMonth()
							&& now.getYear() == lastDate.getYear()) {
						// 今天参加过此活动
						if (activity.getDailyTimes() >= activity.getType()
								.getMaxDailyTimes()) {
							return MmochatUtil.closeWindowAndShowMsgbox(req
									.getHallState(), MmochatUtil.wrapColor(
									member.getName(), Color.green)
									+ "今天已经杀了"
									+ activity.getType().getMaxDailyTimes()
									+ "次人，请先休息一会!",
									MmochatConstant.TLV_WIN_CLICKROLE);
						} else {
							times = activity.getDailyTimes();
							activity.addDailyTimes(1);
						}
					} else {
						// 今天没有参加过此活动
						times = 0;
						activity.setLastTime(now.getTime());
						activity.setDailyTimes(1);
					}
				}
				maxTimes = Math.max(maxTimes, times);
			}
			maxTimes++;
			int sn = MmochatConstant.moneyCostToKillPerson + 50000 * maxTimes
					* (maxTimes - 1) / 2;
			sn = Math.max(sn, MmochatConstant.moneyCostToKillPerson);
			int hisTeamNum = Math.max(1, targetList.size());
			int moneyNeed = sn * hisTeamNum;

			if (me.getSmall_money() < moneyNeed) {
				return MmochatUtil.msgbox(req.getHallState(), "您包裹中没有"
						+ MmochatUtil.getColorMoney(moneyNeed) + "文钱，无法进行杀戮!");
			}
			int oldMoney = (int) me.getSmall_money();
			me.addAndUpdateSmall_money(-1 * moneyNeed);
			try {
				MmochatDao.updateRoleSmallMoney(me);
			} catch (Exception e) {
				e.printStackTrace();
				me.setSmall_money(oldMoney);
				me.addAndUpdateSmall_money(0);
				return MmochatUtil.msgbox(req.getHallState(), "服务器忙，请稍候再试!");
			}

			// 进入战斗
			MmochatBattleService
					.enterPVPBattle(me.getMapId(), (byte) me.getLine(),
							requestList, targetList, MmochatBattleType.强制杀戮);
		} else {
			return MmochatUtil.msgbox(req.getHallState(), "当前地图不允许强制杀戮!");
		}
		return null;
	}

	// 称谓列表
	private CreateTlvWin getChenHaoTlv(MmochatPlayer me) {
		CreateTlvWin tlv = new CreateTlvWin();
		tlv.setWinType(WinType.List);
		tlv.setTitle("称谓列表");
		tlv.setRightName("返回");
		tlv.setLeftName("选择");
		tlv.setWinHeight(230);
		tlv.setWinId(MmochatConstant.TLV_WIN_CHENHAO);
		tlv.addRightTLV(new CloseWinTLV(MmochatConstant.TLV_WIN_CHENHAO));

		if (me.getCurChenHao() == null) {
			tlv.addItemEvent("无" + MmochatUtil.wrapColor(" √", Color.yellow),
					new ClearDataTLV(), new AddDataTLV((int) -1));
		} else {
			tlv.addItemEvent("无", new ClearDataTLV(), new AddDataTLV((int) -1));
		}

		for (MmochatChenHao chenhao : me.getChenHaoMap().values()) {
			String item = chenhao.getName();
			if (chenhao.isInUse()) {
				item += MmochatUtil.wrapColor(" √", Color.yellow);
			}
			String extra = "";
			if (chenhao.getExtraEffectInfo() != null) {
				extra += "\n" + chenhao.getExtraEffectInfo();
			}
			for (MmochatEquipAttribute attr : chenhao.getExtraAttr()) {
				extra += "\n" + attr.getType().getStartInfo() + "+"
						+ attr.getValue() + attr.getType().getEndInfo();
			}
			if (extra.length() > 0) {
				item += MmochatUtil.wrapColor(extra, Color.green);
			}
			tlv.addItemEvent(item, new ClearDataTLV(), new AddDataTLV(
					(int) chenhao.getType().getKey()));
		}
		tlv.addLeftTLV(new SendDataTLV(MmochatConstant.getClientModuleId(),
				MmochatMain.getModuleInstID(),
				MmochatConstant.MSGCODE_MMOCHAT_C_6_22, (int) me.getRoleId()));
		tlv.addLeftTLV(new ShowWaitingMsgBoxTLV());
		return tlv;
	}

	// 6.21 查看称谓列表
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_21(SkymobiHandler handler,
			Mmochat_6_21C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			// 在其它服，不处理
			return MmochatUtil.msgbox(req.getHallState(), "当前位于跨服区，无法进行此操作!");
		}
		if (me.getChenHaoMap().size() == 0) {
			return MmochatUtil.msgbox(req.getHallState(), "没有可选的称谓!");
		}

		CreateTlvWin tlv = getChenHaoTlv(me);
		return MmochatUtil.tlvResponse(req.getHallState(), tlv);
	}

	// 6.22 设置称谓列表
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_22(SkymobiHandler handler,
			Mmochat_6_22C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			// 在其它服，不处理
			return MmochatUtil.msgbox(req.getHallState(), "当前位于跨服区，无法进行此操作!");
		}
		if (me.getChenHaoMap().size() == 0) {
			return MmochatUtil.msgbox(req.getHallState(), "没有可选的称谓!");
		}

		for (MmochatChenHao c : me.getChenHaoMap().values()) {
			if (c.isInUse()) {
				if (c.getType().getKey() == req.getChenhaoType()) {
					return MmochatUtil.msgbox(req.getHallState(), "当前已经是此称谓了!");
				}
				c.setInUse(false);
			}
		}
		MmochatChenHaoType type = MmochatChenHaoType.get(req.getChenhaoType());
		MmochatChenHao chenhao = null;
		if (type != null) {
			chenhao = me.getChenHaoMap().get(type);
			if (chenhao != null) {
				chenhao.setInUse(true);
			}
		}

		try {
			MmochatDao.saveChenhao(me);
		} catch (Exception e) {
			e.printStackTrace();
		}
		Mmochat_1_10S pack = new Mmochat_1_10S();
		pack.setMe(me);
		MmochatUtil.sendCommonPack(me, pack);

		CreateTlvWin tlv = getChenHaoTlv(me);
		return MmochatUtil.tlvResponse(req.getHallState(), new CloseWinTLV(
				MmochatConstant.TLV_WIN_CHENHAO), tlv);
	}

	@SkymobiService
	public SkymobiProtocolMessage handleC_6_24(SkymobiHandler handler,
			Mmochat_6_24C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		String info = req.getInfo();
		if (info == null || info.length() == 0) {
			return MmochatUtil.msgbox(req.getHallState(), "没有找到此用户!");
		}
		int index = req.getIndex();
		if (index == 1) {
			CreateTlvWin tlv = new CreateTlvWin();
			tlv.setWinType(WinType.List);
			tlv.setTitle("查找结果");
			tlv.setRightName("返回");
			tlv.setLeftName("查看");
			tlv.setWinHeight(250);
			tlv.addRightTLV(new CloseWinTLV());

			// 按名字查找:先全名匹配
			Integer roleId = MmochatMainService.nameMap.get(info);
			if (roleId != null) {
				MmochatPlayer member = MmochatMainService.players.get(roleId);
				if (member != null) {
					String item = "";
					item += MmochatUtil.wrapColor(member.getName(),
							Color.yellow);
					item += "\n" + member.getLevel() + "级,";
					item += member.getFamily().getName();
					tlv.addItemEvent(member.getBmpId(), item,
							new ClearDataTLV(), new AddDataTLV((int) roleId));
				}
			}
			// 再部分匹配，最多列出20个
			int count = 0;
			for (MmochatPlayer member : MmochatMainService.players.values()) {
				if (roleId != null && roleId == member.getRoleId()) {
					continue;
				}
				if (member.getName().contains(info)) {
					String item = "";
					item += MmochatUtil.wrapColor(member.getName(),
							Color.yellow);
					item += "\n" + member.getLevel() + "级,";
					item += member.getFamily().getName();
					tlv.addItemEvent(member.getBmpId(), item,
							new ClearDataTLV(), new AddDataTLV((int) member
									.getRoleId()));
					count++;
					if (count >= 20) {
						break;
					}
				}
			}
			if (roleId == null && count == 0) {
				return MmochatUtil.msgbox(req.getHallState(),
						"在线用户中没有找到此用户，或名字中包含" + info
								+ "的用户，请确认输入是否正确，如果此用户当前不在线，也将查询不到!");
			}

			tlv.addLeftTLV(new AddDataTLV((int) me.getRoleId()));
			tlv.addLeftTLV(new SendDataTLV(MmochatConstant.getClientModuleId(),
					MmochatMain.getModuleInstID(),
					MmochatConstant.MSGCODE_MMOCHAT_C_6_1, (int) 4));
			tlv.addLeftTLV(new ShowWaitingMsgBoxTLV());

			return MmochatUtil.tlvResponse(req.getHallState(), tlv);
		} else if (index == 2) {
			// 按ID查找
			int id;
			try {
				id = (Integer.parseInt(info, 16)) / 3;

				CreateTlvWin tlv = new CreateTlvWin();
				tlv.setWinType(WinType.List);
				tlv.setTitle("查找结果");
				tlv.setRightName("返回");
				tlv.setLeftName("查看");
				tlv.setWinHeight(250);
				tlv.addRightTLV(new CloseWinTLV());

				MmochatPlayer member = MmochatMainService.players.get(id);
				if (member != null) {
					String item = "";
					item += MmochatUtil.wrapColor(member.getName(),
							Color.yellow);
					item += "\n" + member.getLevel() + "级,";
					item += member.getFamily().getName();
					tlv.addItemEvent(member.getBmpId(), item,
							new ClearDataTLV(), new AddDataTLV((int) id));
				} else {
					return MmochatUtil.msgbox(req.getHallState(),
							"在线用户中没有找到此用户，请确认ID是否正确，如果此用户当前不在线，也将查询不到!");
				}
				tlv.addLeftTLV(new AddDataTLV((int) me.getRoleId()));
				tlv.addLeftTLV(new SendDataTLV(MmochatConstant
						.getClientModuleId(), MmochatMain.getModuleInstID(),
						MmochatConstant.MSGCODE_MMOCHAT_C_6_1, (int) 4));
				tlv.addLeftTLV(new ShowWaitingMsgBoxTLV());

				return MmochatUtil.tlvResponse(req.getHallState(), tlv);
			} catch (NumberFormatException e) {
				return MmochatUtil.msgbox(req.getHallState(),
						"请输入正确的ID!ID只能由0~9、a~f组成。");
			}
		} else {
			return MmochatUtil.msgbox(req.getHallState(), "暂不支持此功能!");
		}
	}

	// 6.25 编辑玩家心情
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_25(SkymobiHandler handler,
			Mmochat_6_25C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (!me
				.getOtherSystemSettingByType(MmochatOtherSystemSettingType.允许编辑心情)) {
			return MmochatUtil.msgbox(req.getHallState(),
					"由于您的诚信出现问题，您目前不能编辑心情!");
		}
		String userMsg = req.getInfo();
		if (userMsg.contains("") || userMsg.contains("")
				|| userMsg.contains("") || userMsg.contains("")) {
			return MmochatUtil.msgbox(req.getHallState(), "内容中不能包含不可见字符!");
		}
		if (userMsg.length() > 35) {
			return MmochatUtil.msgbox(req.getHallState(), "字数不能超过35个!当前字数为"
					+ userMsg.length() + "!");
		}
		String msg = MmochatFilterService.getFilterString(userMsg);
		String oldMood = me.getMoodInfo();
		me.setMoodInfo(msg);
		try {
			MmochatDao.updateMood(me);
		} catch (Exception e) {
			e.printStackTrace();
			me.setMoodInfo(oldMood);
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		return MmochatUtil.msgbox(req.getHallState(), "心情编辑成功!重新查看资料时即可更新。");
	}

	// 禁言
	@SuppressWarnings("deprecation")
	@SkymobiService
	public SkymobiProtocolMessage handleC_6_26(SkymobiHandler handler,
			Mmochat_6_26C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}

		// 检测是否有禁言的权力
		boolean hasChenhao = false;
		for (MmochatChenHao chenhao : me.getChenHaoMap().values()) {
			if (chenhao.getType() == MmochatChenHaoType.试道王者
					&& !chenhao.isTimeOut()) {
				hasChenhao = true;
				break;
			}
		}
		if (!hasChenhao) {
			return MmochatUtil.msgbox(req.getHallState(),
					"只有拥有试道王者称号的玩家，才有禁言权!");
		}

		// 今天禁言次数
		Date now = new Date();
		MmochatDailyActivity daily = me.getDailyActivities().get(
				MmochatDailyActivityType.禁言);
		if (daily != null
				&& daily.getDailyTimes() >= daily.getType().getMaxDailyTimes()) {
			Date lastDate = new Date(daily.getLastTime());
			if (now.getDate() == lastDate.getDate()
					&& now.getMonth() == lastDate.getMonth()
					&& now.getYear() == lastDate.getYear()) {
				// 今天已经禁言次数满了
				return MmochatUtil.msgbox(req.getHallState(), "每天可禁言"
						+ daily.getType().getMaxDailyTimes() + "次，您今天禁言次数已满!");
			}
		}
		if (me.getRoleId() == req.getHisRoleId()) {
			return MmochatUtil.msgbox(req.getHallState(), "不能对自己禁言!");
		}

		MmochatPlayer he = MmochatMainService.players.get(req.getHisRoleId());
		if (he == null) {
			return MmochatUtil.msgbox(req.getHallState(), "该玩家当前不在线!");
		}
		MmochatLockChatData lockChat = MmochatConstant.forbiddenRoleIdToChat
				.get(he.getRoleId());
		if (lockChat != null) {
			if (lockChat.getFreeTime() > System.currentTimeMillis()) {
				// 仍在禁言中
				return MmochatUtil.msgbox(req.getHallState(),
						"对方当前已经被禁言，不可重复禁言!");
			}
		}

		// 对方是否也是试道王者
		hasChenhao = false;
		for (MmochatChenHao chenhao : he.getChenHaoMap().values()) {
			if (chenhao.getType() == MmochatChenHaoType.试道王者
					&& !chenhao.isTimeOut()) {
				hasChenhao = true;
				break;
			}
		}
		if (hasChenhao) {
			return MmochatUtil.msgbox(req.getHallState(), "对方为试道王者，您无法对其进行禁言!");
		}

		// 扣除禁言次数
		if (daily == null) {
			// 第一次
			daily = new MmochatDailyActivity();
			daily.setType(MmochatDailyActivityType.禁言);
			daily.setLastTime(System.currentTimeMillis());
			daily.setDailyTimes(1);
			me.addDailyActivity(daily);
		} else {
			Date lastDate = new Date(daily.getLastTime());
			if (now.getDate() == lastDate.getDate()
					&& now.getMonth() == lastDate.getMonth()
					&& now.getYear() == lastDate.getYear()) {
				daily.addDailyTimes(1);
				daily.setLastTime(System.currentTimeMillis());
			} else {
				daily.setDailyTimes(1);
				daily.setLastTime(System.currentTimeMillis());
			}
		}

		lockChat = new MmochatLockChatData();
		String reason = "您被" + MmochatUtil.wrapColor(me.getName(), Color.green)
				+ "禁言了!";
		long ms = System.currentTimeMillis() + MmochatConstant.MS_PER_MINUTE
				* 10;
		lockChat.setFreeTime(ms);
		lockChat.setReason(reason);

		MmochatConstant.forbiddenRoleIdToChat.put(he.getRoleId(), lockChat);

		String sysInfo = MmochatUtil.wrapColor(he.getName(), Color.green)
				+ "被试道王者" + MmochatUtil.wrapColor(me.getName(), Color.yellow)
				+ "禁言10分钟!";
		MmochatChatService.sendSystemMsg(sysInfo);

		return MmochatUtil.msgbox(req.getHallState(),
				"禁言成功!对方已被您在世界和喇叭频道禁止发言10分钟。");
	}
}
